﻿#if UNITY_4_1
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System;
using TConfig;

public class UIManager : MonoBehaviour
{
	static GameObject root;
    static Transform rootTrans;
    static string windowResourcesRootUrl = "GameResources/UI/Dep/Window/";
	
	static string uiRootFolder = "GameResources/UI/";
	static string fontFolder = "GameResources/UI/Base/Font/";
	static string atlasFolder = "GameResources/UI/Base/Atlas/";
	static string materialFolder = "GameResources/UI/Base/Material/";
	static string effectFolder = "GameResources/UI/Base/Effect/";
	static string soundsFolder = "GameResources/UI/Base/Sounds/";
	static string windowFolder = "GameResources/UI/Dep/Window/";
	
	public class UIAsset
	{
		public string filePath;
//		public AssetBundle asset;
	}
	
	public class GameObjectAsset : UIAsset
	{
		public GameObject obj;
	}
	
	public class AtlasAsset : UIAsset
	{
		public UIAtlas atlas;
	}
	
	public class FontAsset : UIAsset
	{
		public UIFont font;
	}
	
	public class MaterialAsset : UIAsset
	{
		public Material material;
	}
	
	public class SoundAsset : UIAsset
	{
		public AudioClip audioClip;
	}
	
	public static UIAtlas defualtAtlas;
	public static UIFont defualtFont;
	public static Material defualtMaterial;
	
    public static Dictionary<string, Window> windows = new Dictionary<string, Window>();
	public static Dictionary<string, GameObjectAsset> windowResourcesList = new Dictionary<string, GameObjectAsset>();
	public static Dictionary<string, AtlasAsset> atlasList = new Dictionary<string, AtlasAsset>();
	public static Dictionary<string, FontAsset> fontList = new Dictionary<string, FontAsset>();
	public static Dictionary<string, MaterialAsset> materialList = new Dictionary<string, MaterialAsset>();
	public static Dictionary<string, GameObjectAsset> effectList = new Dictionary<string, GameObjectAsset>();
	public static Dictionary<string, SoundAsset> soundsList = new Dictionary<string, SoundAsset>();
	
	
	static Dictionary<string, FontRecordes> cacheFontList = new Dictionary<string, FontRecordes>();	//字体资源还没有加载的时候的字体空间缓存
	static Dictionary<string, MaterialRecordes> cacheMaterialList = new Dictionary<string, MaterialRecordes>();//材质资源还没有加载的时候的材质空间缓存
	static Dictionary<string, AtlasRecordes> cacheAtlasList = new Dictionary<string, AtlasRecordes>();//图集资源还没有加载的时候的图集空间缓存
	static Dictionary<string, SoundsRecordes> cacheSoundsList = new Dictionary<string, SoundsRecordes>();//声音资源还没有加载的时候的声音空间缓存
	
	public static List<Window> openedSecondWindowList = new List<Window>();		//二级窗口列表
	public static List<Window> openedWindowListWhenOpen = new List<Window>();	//当窗口打开时，已打开的其他窗口列表
	public static bool IsFastKeyHiddeAllUI = false;								//快捷键关闭所有UI，用于无UI浏览场景或截屏
	public static Dictionary<string, WaitForUnloadWindow> waitforUnloadWindowList = new Dictionary<string, WaitForUnloadWindow>();		//窗口资源释放缓存链表，防止连续开关同一窗口时的卡顿现象
	public static float waitforUnloadTime = 3.0f;
	
	public bool expanedWindows = true;
	
	//是否有全屏窗口打开
	public static bool fullScreenWindowOpen
	{
		get
		{
			foreach(Window window in windows.Values)
			{
				if(window.fullScreenWindow && window.Visible)
					return true;
			}
			
			return false;
		}
	}
	
	public static Window lastFocusWindow = null;
	public static Window currentFocusWindow = null;
	public static int screenLastWidth = 1024;
	public static int screenLastHeight = 768;
	
	public bool forcePerfectPixel = false;
	
	public static readonly string uiFitName = ".uitresource";
	static char[] fileTrimStart;
	static UIManager instance;
	static public UIManager GetInst()
	{
		return instance;
	}
    void Awake()
    {
		instance = this;
		
        GameObject caObj = GameObject.Find("UI Camera");
		if(caObj != null)
			rootTrans = caObj.transform;
    }
	
	void OnDestroy()
	{
		windows.Clear();
		atlasList.Clear();
		fontList.Clear();
		materialList.Clear();
		effectList.Clear();
		soundsList.Clear();
	}
	
    void Update()
    {	
		foreach(Window window in windows.Values)
		{
			if(window.Visible)
				window.OnUpdate();
		}
		
		if(screenLastWidth != Screen.width || screenLastHeight != Screen.height)
		{
			screenLastWidth = Screen.width;
			screenLastHeight = Screen.height;
			
			foreach(Window window in windows.Values)
			{
				window.OnScreenSizeChanged();
			}
		}
			
		if(forcePerfectPixel)
    		MakeAllUIPerfectPixel();
    }
	
	/// <summary>
	/// 窗口鼠标聚焦处理
	/// </summary>
	void LateUpdate()
	{		
		if(lastFocusWindow != currentFocusWindow)
		{
			if(lastFocusWindow != null)
				lastFocusWindow.OnLostFocus();
			
			if(currentFocusWindow != null)
				currentFocusWindow.OnFocus();
			
			lastFocusWindow = currentFocusWindow;
		}
	}
	
	public static void AutoReleasUnusedResources()
	{
		//窗口资源释放
		if(waitforUnloadWindowList.Count > 0)
		{
			List<string> keys = new List<string>(waitforUnloadWindowList.Keys);
			foreach(string key in keys)
			{
				WaitForUnloadWindow unloadWindow = waitforUnloadWindowList[key];
				if(Time.time - unloadWindow.callUnloadTime >= waitforUnloadTime)
				{
					UnLoadWindowControlAssets(unloadWindow.window);
					waitforUnloadWindowList.Remove(key);
				}
			}
		}
	}

	
	//UI事件处理
	void OnGUI()
	{		
		Event e = Event.current;
		if(e != null)
		{
			mIsKeyEvent = e.isKey;
			mIsMouseEvent = e.isMouse;

			if(e.type == EventType.MouseDown)
			{
				currentFocusWindow = UIManager.GetHoveredWindow();
			}
		}
		else
		{
			//当然消息为空
			mIsKeyEvent = false;
			mIsMouseEvent = false;
		}
		
		if(GUILayout.Button(" Init Load SceneInfo "))
		{
			TMapManager.GetInstace().LoadMapInfo("Scene01");
		}
	}
	
	public static void ReadyToLoadScene()
	{
		foreach(Window window in windows.Values)
			window.OnReadyToLoadScene();
	}
	
	public static void MakeAllUIPerfectPixel()
	{
		if (windowRoot != null)
        {
            for (int i = 0; i < windowRoot.childCount; i++)
            {
                Transform child = windowRoot.GetChild(i);
                MakeUINodePerfectPixelPosition(child, true);
            }
        }
	}

    public static void MakeUINodePerfectPixelPosition(Transform trans, bool toChildren)
    {
		if(trans == null)
			return;
		
        bool rePosition = true;
		if(LayerMask.LayerToName(trans.gameObject.layer) != "U2D")
		{
			rePosition = false;
			toChildren = false;
		}
		else
		{
	        if (trans.GetComponent<UIAnchor>() != null)
	            rePosition = false;
			
			UIWidget widget = trans.GetComponent<UIWidget>();
	        if (widget != null)
			{
	            rePosition = false;
				toChildren = false;
				widget.MakePositionPerfect();
			}
		}

        if (rePosition)
        {
            Vector3 pos = trans.localPosition;
            pos.x = Mathf.RoundToInt(pos.x);
            pos.y = Mathf.RoundToInt(pos.y);
//          pos.z = Mathf.CeilToInt(pos.z);

            trans.localPosition = pos;
        }
		
		if(toChildren)
		{
			if(trans.GetComponent<UITable>() != null)
				toChildren = false;
			if(trans.GetComponent<UIGrid>() != null)
				toChildren = false;
//			if(trans.GetComponent<UIMix>() != null)
//				toChildren = false;
		}
		
		if(toChildren)
		{
	        for (int i = 0; i < trans.childCount; i++)
	        {
	            Transform child = trans.GetChild(i);
	            MakeUINodePerfectPixelPosition(child, toChildren);
	        }
		}
    }
		
	public static GameObject uiRoot
	{
		get
		{
			if(root == null)
				root = GameObject.Find("UI Root (2D)");
			
			return root;
		}
	}
	
	public static Transform windowRoot
	{
		get
		{
			if(rootTrans == null)
				if(uiRoot != null)
					rootTrans = uiRoot.transform.FindChild("UI Camera");
			
			return rootTrans;
		}
	}
	
	#region //UI Event
	/// <summary>
	/// 检测是否为UI事件
	/// </summary>
	public static bool IsUIEvent
	{	
		get
		{
			return (IsPressDownUI 
				|| IsPressingUI 
				|| IsDraggingUI 
				|| IsPressUpUI 
				|| IsUIInput 
				|| fullScreenWindowOpen);
		}
	}
	
    /// <summary>
    /// 检测是否为悬停在UI上事件 
    /// </summary>
    public static bool IsMouseOnUI
    {
        get
        {
			if(fullScreenWindowOpen)
				return true;
			
            GameObject hoverObject = UICamera.hoveredObject;
			if(hoverObject == null)
				return false;
			else if(hoverObject.name.StartsWith("IgnoreUI-"))
				return false;
			
			Window window = GetHoveredWindow();
			if(window == null)
			{
				Debug.LogError("UI不能脱离窗口而存在！ UIControl：" + hoverObject.name, hoverObject);
				return false;
			}
			
			if(!window.Visible)
			{
				return false;
			}
            return true;
        }
    }
	
	/// <summary>
	/// 检测是否为刚按下UI事件
	/// </summary>
	public static bool IsPressDownUI
	{
		get
		{
			if(IsMouseDown && IsMouseOnUI)
				return true;
			
			return false;
		}
	}
	
	/// <summary>
	/// 检测否为UI按下状态
	/// </summary>
	public static bool IsPressingUI
	{
		get
		{
			if(IsMousePressed && GetPressedControl() != null)
				return true;
			
			return false;
		}
	}
	
	/// <summary>
	/// 检测是否为点击UI事件
	/// </summary>
	public static bool IsPressUpUI
	{
		get
		{			
			if(IsMouseUp && GetSelectedControl() != null)
				return true;			
			
			return false;
		}
	}
	
	/// <summary>
	/// 检测是否在拖拽UI
	/// </summary>
	public static bool IsDraggingUI
	{
		get
		{
			if(IsMousePressed && GetDragedControl() != null)
				return true;
			
			return false;
		}
	}
	
	/// <summary>
	/// 检测鼠标是否为刚按下状态
	/// </summary>
	public static bool IsMouseDown
	{
		get
		{
			return (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2));
		}
	}
	
	/// <summary>
	/// 检测鼠标是否为按下状态
	/// </summary>
	public static bool IsMousePressed
	{
		get
		{
			return (Input.GetMouseButton(0) || Input.GetMouseButton(1) || Input.GetMouseButton(2));
		}
	}
	
	// <summary>
	/// 检测鼠标是否为刚弹起状态
	/// </summary>
	public static bool IsMouseUp
	{
		get
		{
			return (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1) || Input.GetMouseButtonUp(2));
		}
	}
	
	/// <summary>
	/// 检测是否为按键信息
	/// </summary>
	private static bool mIsKeyEvent = false;
	public static bool IsKeyEvent
	{
		get
		{
			return mIsKeyEvent;
		}
	}
	
	/// <summary>
	/// 检测是否为鼠标事件
	/// </summary>
	private static bool mIsMouseEvent = false;
	public static bool IsMouseEvent
	{
		get
		{
			return mIsMouseEvent;
		}
	}
	
	/// <summary>
	/// 检测是否为UIInput事件
	/// </summary>
	public static bool IsUIInput
	{
		get
		{ 
			return (UICamera.inputHasFocus);
		}
	}
    #endregion  //UI Event
	
	
    #region //UI Init
    /// <summary>
    /// 初始化窗口管理类
    /// </summary>
    public void Init()
    {
		fileTrimStart = "Assets/".ToCharArray();
		
		LoadDefualtResources();
		
//		LoadWindow();
		
		InitLoadXML();
    }
	
	void LoadDefualtResources()
	{
//		defualtAtlas = GetAtlas("MainWindowAtlas");
//		defualtFont = GetFont("Micro_12_bold");
//		defualtMaterial = GetMaterial("3DAvatar");
	}
	
	void InitLoadXML()
	{
		LoaderManager.GetInstance().InitLoadXML("System/UI_windowList.xml", LoaderManager.LoadTypeEnum.Window);
	}
	
	/// <summary>
	/// 加载窗口资源
	/// </summary>
	void LoadWindow()
	{
		string folder = GameResources.RootPath + windowFolder;
		string[] files = Directory.GetFiles(folder, "*" + uiFitName, SearchOption.AllDirectories);
        for(int i = 0; i < files.Length; i++)
		{			
			string file = files[i];
			InstantiateWindow(file);
		}
	}
	
	public static void InstantiateWindow(GameObject go)
	{
		if(go == null)
		{
			Debug.LogError("go is null");
			return;
		}
		
		Window window = go.GetComponent<Window>();
		if(window==null)
		{
			Debug.LogError(string.Format("{0}:没有挂WINDOW脚本", go.name));
			DestroyImmediate(go);
			return;
		}		
		
		if(windows.ContainsKey(go.name))
		{
			Debug.Log(string.Format("已经存在窗口：{0}！", go.name));
			DestroyImmediate(go);
			return;
		}
		else
		{
			windows.Add(go.name, window);
		}
	
		Transform windowTrans = go.transform;	
		windowTrans.parent = windowRoot;
		windowTrans.localPosition = Vector3.zero;
        windowTrans.localRotation = Quaternion.identity;
        windowTrans.localScale = Vector3.one;
		
		go.SetActive(false);
	}
	
	static void InstantiateWindow(string file)
	{
		try
		{
			string windowName = Path.GetFileNameWithoutExtension(file).ToLower();
			GameObject prefab = GetWindowAsset(windowName);
	        if (prefab == null)
	        {
	            Debug.LogError("[UI]: The " + prefab.name + " resource has some problem ! (where : " + file + ")");
	            return;
	        }

       		GameObject windowObj = MonoBehaviour.Instantiate(prefab) as GameObject;

		
        	windowObj.name = windowName;
			Window window = windowObj.GetComponent<Window>();
			if(window==null)
			{
				Debug.LogError(string.Format("{0}:没有挂WINDOW脚本", windowName));
				DestroyImmediate(windowObj);
				return;
			}		
			
			if(windows.ContainsKey(windowName))
			{
				Debug.Log(string.Format("已经存在窗口：{0}！", windowName));
				DestroyImmediate(windowObj);
				return;
			}
			else
			{
				windows.Add(windowName, window);
			}
		
			Transform windowTrans = windowObj.transform;	
			windowTrans.parent = windowRoot;
			windowTrans.localPosition = Vector3.zero;
	        windowTrans.localRotation = Quaternion.identity;
	        windowTrans.localScale = Vector3.one;
			
//			window.Init();
			
			windowObj.SetActive(false);
		}
		catch(Exception e)
		{
			Debug.LogException(e);
		}
		finally
		{
		}
	}
	
	public static void LoadWindowAssets(Window window)
	{
		if(waitforUnloadWindowList.ContainsKey(window.name))
			waitforUnloadWindowList.Remove(window.name);
		
		//资源查找缓存
		Dictionary<string, FontRecordes> fontList = new Dictionary<string, FontRecordes>();
		Dictionary<string, AtlasRecordes> atlasList = new Dictionary<string, AtlasRecordes>();
		Dictionary<string, MaterialRecordes> materialList = new Dictionary<string, MaterialRecordes>();
		Dictionary<string, SoundsRecordes> soundList = new Dictionary<string, SoundsRecordes>();
		Dictionary<string, U3DRecordes> u3dObjectList = new Dictionary<string, U3DRecordes>();
		
		GameObject windowObj = window.gameObject;
		List<UIWidget> widgets = NGUITools.FindInChildren<UIWidget>(windowObj);
		foreach(UIWidget widget in widgets)
		{
			string srcPath = widget.srcPath;
			if(!string.IsNullOrEmpty(srcPath))
			{
				if(widget is UILabel)
				{
					UILabel label = widget as UILabel;
	//				label.font = GetFont(srcPath);
					
					if(label.mustLoad)
					{
						label.mustLoad = false;
						if(!fontList.ContainsKey(srcPath))
							fontList.Add(srcPath, new FontRecordes());
						fontList[srcPath].labelList.Add(label);
					}
				}
				else if(widget is UISprite)
				{
					UISprite sprite = widget as UISprite;
	//				sprite.atlas = GetAtlas(srcPath);
					
					if(sprite.mustLoad)
					{
						sprite.mustLoad = false;
						if(!atlasList.ContainsKey(srcPath))
							atlasList.Add(srcPath, new AtlasRecordes());
						atlasList[srcPath].spriteList.Add(sprite);
					}
				}
				else if(widget is UITexture)
				{
					UITexture texture = widget as UITexture;
	//				texture.material = GetMaterial(srcPath);
					
					if(texture.mustLoad)
					{
						texture.mustLoad = false;
						if(!materialList.ContainsKey(srcPath))
							materialList.Add(srcPath, new MaterialRecordes());
						materialList[srcPath].textureList.Add(texture);
					}
				}
			}
		}
		
//		List<UIMix> mixs = NGUITools.FindInChildren<UIMix>(windowObj);
//		foreach(UIMix mix in mixs)
//		{
////			mix.defaultFont = GetFont(mix.defaultFontSrcPath);
//			string defaultFontSrcPath = mix.defaultFontSrcPath;
//			if(!string.IsNullOrEmpty(defaultFontSrcPath))
//			{
//				if(!fontList.ContainsKey(defaultFontSrcPath))
//					fontList.Add(defaultFontSrcPath, new FontRecordes());
//				fontList[defaultFontSrcPath].mixDefualtFontList.Add(mix);
//			}
////			mix.defaultAtlas = GetAtlas(mix.defaultAtlasSrcPath);	
//			string defaultAtlasSrcPath = mix.defaultAtlasSrcPath;
//			if(!string.IsNullOrEmpty(defaultAtlasSrcPath))
//			{
//				if(!atlasList.ContainsKey(defaultAtlasSrcPath))
//					atlasList.Add(defaultAtlasSrcPath, new AtlasRecordes());
//				atlasList[defaultAtlasSrcPath].mixDefualtAtlasList.Add(mix);
//			}
//			
//			for(int i = 0; i < mix.fontSrcPathList.Count; i++)
//			{
////				UIFont font = GetFont(mix.fontSrcPathList[i]);
////				mix.fontList.Add(font); 
//				string fontSrcPath = mix.fontSrcPathList[i];
//				if(!string.IsNullOrEmpty(fontSrcPath))
//				{
//					if(!fontList.ContainsKey(fontSrcPath))
//						fontList.Add(fontSrcPath, new FontRecordes());
//					fontList[fontSrcPath].mixOtherFontList.Add(mix);
//				}				
//			}
//			for(int i = 0; i < mix.atlasSrcPathList.Count; i++)
//			{
////				UIAtlas atlas = GetAtlas(mix.atlasSrcPathList[i]);
////				mix.atlasList.Add(atlas); 
//				string atlasSrcPath = mix.atlasSrcPathList[i];
//				if(!string.IsNullOrEmpty(atlasSrcPath))
//				{
//					if(!atlasList.ContainsKey(atlasSrcPath))
//						atlasList.Add(atlasSrcPath, new AtlasRecordes());
//					atlasList[atlasSrcPath].mixOtherAtlasList.Add(mix);
//				}
//			}
//		}
		
		List<UIPopupList> popList = NGUITools.FindInChildren<UIPopupList>(windowObj);
		foreach(UIPopupList pop in popList)
		{
//			pop.font = GetFont(pop.fontSrcPath);
			string fontSrcPath = pop.fontSrcPath;
			if(!string.IsNullOrEmpty(fontSrcPath))
			{
				if(!fontList.ContainsKey(fontSrcPath))
					fontList.Add(fontSrcPath, new FontRecordes());
				fontList[fontSrcPath].popList.Add(pop);
			}
			
//			pop.atlas = GetAtlas(pop.atlasSrcPath);
			string atlasSrcPath = pop.atlasSrcPath;
			if(!string.IsNullOrEmpty(atlasSrcPath))
			{
				if(!atlasList.ContainsKey(atlasSrcPath))
					atlasList.Add(atlasSrcPath, new AtlasRecordes());
				atlasList[atlasSrcPath].popList.Add(pop);
			}
		}
		
		List<UIButtonSound> bSounds = NGUITools.FindInChildren<UIButtonSound>(windowObj);
		foreach(UIButtonSound bsound in bSounds)
		{
//			bsound.audioClip = GetAudio(bsound.srcPath);
			string srcPath = bsound.srcPath;
			if(!string.IsNullOrEmpty(srcPath))
			{
				if(!soundList.ContainsKey(srcPath))
					soundList.Add(srcPath, new SoundsRecordes());
				soundList[srcPath].soundList.Add(bsound);
			}
		}
		
//		List<UI3D> u3dList = NGUITools.FindInChildren<UI3D>(windowObj);
//		foreach(UI3D u3d in u3dList)
//		{
//			if(u3d.autoLoadAndRelease || !u3d.inited)
//			{
//				string srcPath = u3d.srcPath;
//				if(!string.IsNullOrEmpty(srcPath))
//				{
//					if(!u3dObjectList.ContainsKey(srcPath))
//						u3dObjectList.Add(srcPath, new U3DRecordes());
//					u3dObjectList[srcPath].u3dList.Add(u3d);
//				}
//			}
//		}
		
		//通过缓存执行资源替换
		foreach(string filePath in fontList.Keys)
		{
			UIFont font = GetFont(filePath);
			if(font != null)
			{
				FontRecordes recordes = fontList[filePath];
				foreach(UILabel label in recordes.labelList)
				{
					label.font = font;
				}
//				foreach(UIMix mix in recordes.mixDefualtFontList)
//				{
//					mix.defaultFont = font;
//				}
//				foreach(UIMix mix in recordes.mixOtherFontList)
//				{
//					mix.fontList.Add(font);
//				}
				foreach(UIPopupList pop in recordes.popList)
				{
					pop.font = font;
				}
			}
			else
			{
				string path = GetTrueFilePath(filePath, UIResourcesType.Font);
				cacheFontList.Add(path, fontList[filePath]);
			}
		}
		
		foreach(string filePath in atlasList.Keys)
		{
			UIAtlas atlas = GetAtlas(filePath);
			if(atlas != null)
			{
				AtlasRecordes recordes = atlasList[filePath];
				foreach(UISprite sprite in recordes.spriteList)
				{
					sprite.atlas = atlas;
				}
//				foreach(UIMix mix in recordes.mixDefualtAtlasList)
//				{
//					mix.defaultAtlas = atlas;
//				}
//				foreach(UIMix mix in recordes.mixOtherAtlasList)
//				{
//					mix.atlasList.Add(atlas);
//				}
				foreach(UIPopupList pop in recordes.popList)
				{
					pop.atlas = atlas;
				}
			}
			else
			{
				string path = GetTrueFilePath(filePath, UIResourcesType.Atlas);
				cacheAtlasList.Add(path, atlasList[filePath]);
			}
		}
		foreach(string filePath in materialList.Keys)
		{
			Material material = GetMaterial(filePath);
			if(material != null)
			{
				MaterialRecordes recordes = materialList[filePath];
				foreach(UITexture texture in recordes.textureList)
				{
					texture.material = material;
				}
			}
			else
			{
				string path = GetTrueFilePath(filePath, UIResourcesType.Material);
				cacheMaterialList.Add(path, materialList[filePath]);
			}
		}
		foreach(string filePath in soundList.Keys)
		{
			AudioClip audioClip = GetAudio(filePath);
			if(audioClip != null)
			{
				SoundsRecordes recordes = soundList[filePath];
				foreach(UIButtonSound bsound in recordes.soundList)
				{
					bsound.audioClip = audioClip;
				}
			}
			else
			{
				string path = GetTrueFilePath(filePath, UIResourcesType.Sound);
				cacheSoundsList.Add(path, soundList[filePath]);
			}
		}
//		foreach(string filePath in u3dObjectList.Keys)
//		{
//			GameObject u3dObject = GetEffect(filePath);
//			if(u3dObject != null)
//			{
//				U3DRecordes recordes = u3dObjectList[filePath];
//				foreach(UI3D u3d in recordes.u3dList)
//				{
//					u3d.prefab = u3dObject;
//					GameObject obj = Instantiate(u3dObject) as GameObject;
//					obj.transform.parent = u3d.transform;
//					obj.transform.localPosition = Vector3.zero;
//					obj.transform.localScale = Vector3.one;
//					obj.transform.localRotation = Quaternion.identity;
//					u3d.target = obj;
//					u3d.inited = true;
//					
//					if(u3d.onFinshedLoad != null)
//						u3d.onFinshedLoad();
//				}
//			}
//		}
	}
	
	public class FontRecordes
	{
		public List<UILabel> labelList = new List<UILabel>();
//		public List<UIMix> mixDefualtFontList = new List<UIMix>();
//		public List<UIMix> mixOtherFontList = new List<UIMix>();
		public List<UIPopupList> popList = new List<UIPopupList>();
	}
	
	public class AtlasRecordes
	{
		public List<UISprite> spriteList = new List<UISprite>();
//		public List<UIMix> mixDefualtAtlasList = new List<UIMix>();
//		public List<UIMix> mixOtherAtlasList = new List<UIMix>();
		public List<UIPopupList> popList = new List<UIPopupList>();
	}
	
	public class MaterialRecordes
	{
		public List<UITexture> textureList = new List<UITexture>();
	}
	
	public class SoundsRecordes
	{
		public List<UIButtonSound> soundList = new List<UIButtonSound>();
	}
	
	public class U3DRecordes
	{
//		public List<UI3D> u3dList = new List<UI3D>();
	}
	
	public class WaitForUnloadWindow
	{
		public Window window;
		public float callUnloadTime;
	}
	
	public static void UnLoadWindowAssets(Window window)
	{
		if(window.Visible)
			return;
		
		if(!waitforUnloadWindowList.ContainsKey(window.name))
		{
			WaitForUnloadWindow unloadWindow = new WaitForUnloadWindow();
			unloadWindow.window = window;
			unloadWindow.callUnloadTime = Time.time;
			waitforUnloadWindowList.Add(window.name, unloadWindow);
		}
//		UnLoadWindowControlAssets(window);
	}
	
	public static void UnLoadWindowControlAssets(Window window)
	{
		if(window.Visible)
			return;
		
		window.isUnload = true;
		
		GameObject windowObj = window.gameObject;
		List<UIWidget> widgets = NGUITools.FindInChildren<UIWidget>(windowObj);
		foreach(UIWidget widget in widgets)
		{
			widget.isUnload = true;
			if(widget is UILabel)
			{
				UILabel label = widget as UILabel;
				if(label.font != null)
				{
					label.mustLoad = true;
					label.srcPath = GetFontAssetPath(label.font);
					label.font = defualtFont;
				}
				else
				{		
					label.mustLoad = false;
					label.srcPath = "";
				}
			}
			else if(widget is UISprite)
			{
				UISprite sprite = widget as UISprite;
				if(sprite.atlas != null)
				{
					sprite.mustLoad = true;
					sprite.srcPath = GetAtlasAssetPath(sprite.atlas);
					sprite.atlas = defualtAtlas;
				}
				else
				{
					sprite.mustLoad = false;
					sprite.srcPath = "";
				}
			}
			else if(widget is UITexture)
			{
				UITexture texture = widget as UITexture;
				if(texture.material != null)
				{
					texture.mustLoad = true;
					texture.srcPath = GetMaterialAssetPath(texture.material);
					texture.material = defualtMaterial;
				}
				else
				{
					texture.mustLoad = false;
					texture.srcPath = "";
				}
			}
			widget.isUnload = false;
		}
		
//		List<UIMix> mixs = NGUITools.FindInChildren<UIMix>(windowObj);
//		foreach(UIMix mix in mixs)
//		{
//			if(mix.defaultFont != null)
//			{
//				mix.defaultFontSrcPath = GetFontAssetPath(mix.defaultFont);
//				mix.defaultFont = null;
//			}
//			else
//			{
//				mix.defaultFontSrcPath = "";
//			}
//			if(mix.defaultAtlas != null)
//			{
//				mix.defaultAtlasSrcPath = GetAtlasAssetPath(mix.defaultAtlas);
//				mix.defaultAtlas = null;
//			}
//			else
//			{
//				mix.defaultAtlasSrcPath = "";
//			}
//			
//			mix.fontSrcPathList.Clear();
//			foreach(UIFont font in mix.fontList)
//			{
//				if(font != null)
//				{
//					mix.fontSrcPathList.Add(GetFontAssetPath(font));
//				}
//			}			
//			mix.fontList.Clear();
//			
//			mix.atlasSrcPathList.Clear();
//			foreach(UIAtlas atlas in mix.atlasList)
//			{
//				if(atlas != null)
//				{
//					mix.atlasSrcPathList.Add(GetAtlasAssetPath(atlas));
//				}
//			}
//			mix.atlasList.Clear();
//		}
		
		List<UIPopupList> popList = NGUITools.FindInChildren<UIPopupList>(windowObj);
		foreach(UIPopupList pop in popList)
		{
			if(pop.font != null)
			{
				pop.fontSrcPath = GetFontAssetPath(pop.font);
				pop.font = null;
			}
			else
			{
				pop.fontSrcPath = "";
			}
			
			if(pop.atlas != null)
			{
				pop.atlasSrcPath = GetAtlasAssetPath(pop.atlas);
				pop.atlas = null;
			}
			else
			{
				pop.atlasSrcPath = "";
			}
		}
		
		List<UIButtonSound> bSounds = NGUITools.FindInChildren<UIButtonSound>(windowObj);
		foreach(UIButtonSound bsound in bSounds)
		{
			if(bsound.audioClip != null)
			{
				bsound.srcPath = GetSoundAssetPath(bsound.audioClip);
				bsound.audioClip = null;
			}
			else
			{
				bsound.srcPath = "";
			}
		}
		
//		List<UI3D> u3dList = NGUITools.FindInChildren<UI3D>(windowObj);
//		foreach(UI3D u3d in u3dList)
//		{
//			if(u3d.autoLoadAndRelease)
//			{
//				if(u3d.prefab != null)
//				{					
//					u3d.srcPath = GetEffectAssetPath(u3d.prefab);
//					DestroyImmediate(u3d.target, true);
//					u3d.prefab = null;
//				}
//				else
//					u3d.srcPath = "";
//			}
//		}
		
		UnloadAssetBundles();
	}
	
	static void UnloadAssetBundles()
	{		
//		List<string> removeKey = new List<string>();
//		
//		//Window
//		removeKey.Clear();
//		foreach(string key in windowResourcesList.Keys)
//		{
//			GameObjectAsset assetInfo = windowResourcesList[key];
//			if(assetInfo.asset != null)
//				assetInfo.asset.Unload(false);
//			if(assetInfo.asset == null && assetInfo.obj == null)
//				removeKey.Add(key);
//		}
//		foreach(string key in removeKey)
//			windowResourcesList.Remove(key);
//		
//		//Atlas
//		removeKey.Clear();
//		foreach(string key in atlasList.Keys)
//		{
//			AtlasAsset assetInfo = atlasList[key];
//			if(assetInfo.asset != null)
//				assetInfo.asset.Unload(false);
//			if(assetInfo.asset == null && assetInfo.atlas == null)
//				removeKey.Add(key);
//		}
//		foreach(string key in removeKey)
//			atlasList.Remove(key);
//		
//		//Font
//		removeKey.Clear();
//		foreach(string key in fontList.Keys)
//		{
//			FontAsset assetInfo = fontList[key];
//			if(assetInfo.asset != null)
//				assetInfo.asset.Unload(false);
//			if(assetInfo.asset == null && assetInfo.font)
//				removeKey.Add(key);
//		}
//		foreach(string key in removeKey)
//			fontList.Remove(key);
//		
//		//Material
//		removeKey.Clear();
//		foreach(string key in materialList.Keys)
//		{
//			MaterialAsset assetInfo = materialList[key];
//			if(assetInfo.asset != null)
//				assetInfo.asset.Unload(false);
//			if(assetInfo.asset == null && assetInfo.material == null)
//				removeKey.Add(key);
//		}
//		foreach(string key in removeKey)
//			materialList.Remove(key);
//		
//		//Effect
//		removeKey.Clear();
//		foreach(string key in effectList.Keys)
//		{
//			GameObjectAsset assetInfo = effectList[key];
//			if(assetInfo.asset != null)
//				assetInfo.asset.Unload(false);
//			if(assetInfo.asset == null && assetInfo.obj)
//				removeKey.Add(key);
//		}
//		foreach(string key in removeKey)
//			effectList.Remove(key);
//		
//		//Sound
//		removeKey.Clear();
//		foreach(string key in soundsList.Keys)
//		{
//			SoundAsset assetInfo = soundsList[key];
//			if(assetInfo.asset != null)
//				assetInfo.asset.Unload(false);
//			if(assetInfo.asset == null && assetInfo.audioClip == null)
//				removeKey.Add(key);
//		}
//		foreach(string key in removeKey)
//			soundsList.Remove(key);
		
		//暂时不用这个，会卸载掉一些待用的资源
//		Resources.UnloadUnusedAssets();
		
		for(int i = 0; i < 4; i++)
			System.GC.Collect(i, GCCollectionMode.Forced);
	}
	
//	static void UnloadUnsuedAssetRecrode(Dictionary<string, UIAsset> assetList, string filePath)
//	{
//		if(assetList.ContainsKey(filePath))
//		{
//			UIAsset assetInfo = assetList[filePath];
//			if(assetInfo.asset != null)
//				assetInfo.asset.Unload(false);
//			
//			if(assetInfo.asset == null)
//				assetList.Remove(filePath);
//		}
//	}
	
	/// <summary>
	/// 获取已打开二级页面的个数
	/// </summary>
	public static int GetSecondOpenWindowCount()
	{
		return openedSecondWindowList.Count;
	}
	
	public static void CloseLastSecondOpenWindow()
	{
		if(openedSecondWindowList.Count > 0)
		{
			Window window = openedSecondWindowList[openedSecondWindowList.Count - 1];
			window.Close(true);
			openedSecondWindowList.Remove(window);
		}
	}
	
	public static void UpdateSecondWindowDepth()
	{
		for(int i = 0; i < openedSecondWindowList.Count; i++)
		{
//			openedSecondWindowList[i].SetDepth((900 - 50 * i) / 384.0f);	
			openedSecondWindowList[i].SetDepth(900 - 50 * i);
		}
	}

	/// <summary>
	/// 重新加载所有窗口
	/// </summary>
	public static void ReloadAllWindow()
	{		
		foreach(KeyValuePair<string, Window> window in windows)
		{
			window.Value.Clean();
//			GameObject windowObj = window.Value.gameObject;
//			DestroyImmediate(windowObj);
		}
		
		//清理UI相关记录
		CleanTemp();		
		
//		foreach(KeyValuePair<string, GameObject> window in windowResourcesList)
//		{
//			InitWindow(window.Key);
//		}
	}
	
	//清理UI相关记录
	static void CleanTemp()
	{
//		windows.Clear();
		openedSecondWindowList.Clear();
		lastFocusWindow = null;
//		windowLoadedCount = 0;
	}
    #endregion  //UI Init
	
	#region //UINode Active
	
	public static void Activate(Transform trans)
	{
		if(trans == null)
			return;
		
		Window window = NGUITools.FindInParents<Window>(trans.gameObject);
		if(!window.Visible)
			return;
		
		while(trans != null && !trans.gameObject.activeInHierarchy && trans != window.transform)
		{
			trans.gameObject.SetActive(true);
			trans = trans.parent;
		}
	}
	
	public static void SetAactivate(Transform trans, bool active)
	{
		if(active)
			Activate(trans);
		else
			trans.gameObject.SetActive(false);
	}
	
	public static void Activate(GameObject go)
	{
		if(go != null)
			Activate(go.transform);
	}
	
	public static void SetAactivate(GameObject go, bool active)
	{
		if(go != null)
			SetAactivate(go.transform, active);
	}
	
	#endregion //UINode Active
	
	#region //Screen Postion
	/// <summary>
	/// 获取鼠标位置
	/// </summary>
	public static Vector3 GetMousePosition()
	{
		Vector3 pos = Input.mousePosition;
		
		return new Vector3(pos.x, UICamera.mainCamera.pixelHeight - pos.y, pos.z);
	}
	
	/// <summary>
	/// 获取控件在屏幕上的位置
	/// </summary>
	public static Vector3 GetControlScreenPosition(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlScreenPosition(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件在屏幕上的位置
	/// </summary>
	public static Vector3 GetControlScreenPosition(string windowName, string controlName)
	{
		return GetControlScreenPosition(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件在屏幕上的位置
	/// </summary>
	public static Vector3 GetControlScreenPosition(Window window, string controlName)
	{
		return GetControlScreenPosition(GetControl(window, controlName));
	}	
		
	/// <summary>
	/// 获取控件在屏幕上的位置
	/// </summary>
	public static Vector3 GetControlScreenPosition(GameObject control)
	{
		if(control == null)
			return Vector3.zero;
		
		//Camera uiCamera = NGUITools.FindCameraForLayer(control.layer);
		//if(uiCamera == null)
		Camera uiCamera = UICamera.mainCamera;
 
		Vector3 pos = uiCamera.WorldToScreenPoint(control.transform.position);
		return new Vector3(Mathf.RoundToInt(pos.x),  Mathf.RoundToInt(uiCamera.pixelHeight - pos.y), pos.z);
	}
	
	/// <summary>
	/// 获取控件中心点在屏幕上的位置
	/// </summary>
	/// </param>
	public static Vector3 GetControlCenterScreenPosition(GameObject control)
	{
		if(control == null)
			return Vector3.zero;
		
		Vector3 centerPos = GetControlScreenPosition(control) + GetControlCenterPixelOffset(control);
		centerPos.x  = Mathf.RoundToInt(centerPos.x);
		centerPos.y = Mathf.RoundToInt(centerPos.y);
		
		return centerPos;
	}
	
	/// <summary>
	/// 设置控件在屏幕上的位置
	/// </summary>
	public static void SetControlScreenPosition(GameObject control, float x, float y)
	{
		if(control == null)
			return;
		
		//Camera uiCamera = NGUITools.FindCameraForLayer(control.layer);
		//if(uiCamera == null)
		Camera uiCamera = UICamera.mainCamera;
		
		y = uiCamera.pixelHeight - y;
		float z = control.transform.position.z - uiCamera.transform.position.z;		
		control.transform.position = uiCamera.ScreenToWorldPoint(new Vector3(x, y, z));
		
//		Vector3 localPosition = control.transform.localPosition;
//		localPosition.x = Mathf.RoundToInt(localPosition.x);
//		localPosition.y = Mathf.RoundToInt(localPosition.y);
//		localPosition.z = Mathf.RoundToInt(localPosition.z);
//		control.transform.localPosition = localPosition;
		
		NGUITools.MakePixelPosition(control.transform, true);
	}
	
	/// <summary>
    /// 设置控件屏幕坐标
    /// </summary>	
	public static void SetControlScreenPosition(GameObject control, Vector3 pos)
    {
        if(control == null)
			return;
		
//		Camera uiCamera = NGUITools.FindCameraForLayer(control.layer);
//		if(uiCamera == null)
		Camera	uiCamera = UICamera.mainCamera;
		
		pos.y = uiCamera.pixelHeight - pos.y;
		control.transform.position = uiCamera.ScreenToWorldPoint(pos);
		
//		Vector3 localPosition = control.transform.localPosition;
//		localPosition.x = Mathf.RoundToInt(localPosition.x);
//		localPosition.y = Mathf.RoundToInt(localPosition.y);
//		localPosition.z = Mathf.RoundToInt(localPosition.z);
//		control.transform.localPosition = localPosition;
		
		NGUITools.MakePixelPosition(control.transform, true);
    }
	
	/// <summary>
	/// 3D世界坐标转屏幕坐标
	/// </summary>
	public static Vector3 ConvertWorldToScreenPosition(Vector3 pos)
	{
		Camera uiCamera = UICamera.mainCamera;
 
		Vector3 screenPos = uiCamera.WorldToScreenPoint(pos);
		return new Vector3(Mathf.RoundToInt(screenPos.x),  Mathf.RoundToInt(uiCamera.pixelHeight - screenPos.y), screenPos.z);
	}
	#endregion //Scrren Postion
	

	#region //Window
	
	#region //Window Instance
    /// <summary>
    /// 获取窗口
    /// </summary>
    /// <param name="windowName">窗口名</param>
    /// <returns></returns>
    public static Window GetWindow(string windowName)
    {
		windowName = windowName.ToLower();
        if(windows.ContainsKey(windowName))
            return windows[windowName];

        return null;
    }
	
	public static T GetWindow<T>() where T : Window
	{
		return GetWindow<T>(typeof(T).Name);
	}
	
	public static T GetWindow<T>(string windowName) where T : Window
	{
		T window = GetWindow(windowName) as T;
		
		return window;
	}
	#endregion //Window Instance
	
	#region //Window Visible
    /// <summary>
    /// 检测窗口示显示状态
    /// </summary>
    /// <param name="windowName">窗口名</param>
    /// <returns>true显示、false隐藏 </returns>
    public static bool GetWindowVisible(string windowName)
    {
        Window window = GetWindow(windowName);
        if (window != null)
            return window.Visible;

        return false;
    }

    /// <summary>
    /// 隐藏显示窗口
    /// </summary>
    /// <param name="windowName">窗口名</param>
    /// <param name="Visible">true显示、false隐藏 </param>
    public static void SetWindowVisible(string windowName, bool Visible, bool byuser)
    {
        SetWindowVisible(GetWindow(windowName), Visible, byuser);
    }
	
	/// <summary>
	/// 设置窗口显示状态
	/// </summary>
	public static void SetWindowVisible(Window window, bool Visible, bool byuser )
	{
		if(window == null)
			return;
		
		if(Visible)
			window.Open(byuser);
		else
			window.Close(byuser);
	}

    /// <summary>
    /// 隐藏所有窗口
    /// </summary>
    public static void HideAllWindow()
    {
		bool closeFullWindow = false;
		foreach(Window window in windows.Values)
		{
			if(window.fullScreenWindow && window.Visible)
			{
				closeFullWindow = true;
				window.Close(false);
				break;
			}
		}
		
		if(!closeFullWindow)
		{
			openedWindowListWhenOpen.Clear();		
			
	        foreach (Window window in windows.Values)
	        {
				if(window.Visible)
				{
					openedWindowListWhenOpen.Add(window);
	            	window.Close(false);
				}
	        }
		}
    }
	
	public static void HideOtherWindows(Window window)
	{
		openedWindowListWhenOpen.Clear();
		foreach (Window win in windows.Values)
        {
			if(win.Visible && win != window )
			{
				openedWindowListWhenOpen.Add(window);
            	win.Close(false);
			}
			else if( win == window )
			{
				window.Open(false);
			}
        }
	}
	
	public static void HideOtherWindowsList(List<Window> window)
	{
		openedWindowListWhenOpen.Clear();
		foreach (Window win in windows.Values)
        {
			if( win.Visible )
			{
				for(int i=0; i < window.Count; ++i )
				{
					if( win != window[i] )
					{
						openedWindowListWhenOpen.Add(window[i]);
            			win.Close(false);
					}
				}
			}

			for(int i=0; i < window.Count; ++i )
			{
				if( win == window[i] )
				{
					window[i].Open(false);
				}		
			}
        }
	}
	
	public static void ReOpenAllHidenedWindow()
	{
        foreach (Window window in openedWindowListWhenOpen)
        {
			window.Open(false);
		}
	}
	#endregion //Window Visible
	
	#region //Window EventState
	/// <summary>
	/// Gets the selected window.
	/// </summary>
	/// <returns>
	/// The selected window.
	/// </returns>
	public static Window GetSelectedWindow()
	{
		GameObject selectedObject = UICamera.selectedObject;
		if(selectedObject == null)
			return null;
		
		return NGUITools.FindInParents<Window>(selectedObject);
	}
	
	/// <summary>
	/// Gets the name of the selected window.
	/// </summary>
	/// <returns>
	/// The selected window name.
	/// </returns>
	public static string GetSelectedWindowName()
	{
		Window selectedWindow = GetSelectedWindow();
		if(selectedWindow != null)
			return selectedWindow.name;
		
		return null;
	}
	
	/// <summary>
	/// Gets the hovered window.
	/// </summary>
	/// <returns>
	/// The hovered window.
	/// </returns>
	public static Window GetHoveredWindow()
	{
		GameObject hoveredObject = UICamera.hoveredObject;
		if(hoveredObject == null)
			return null;
		
		return NGUITools.FindInParents<Window>(hoveredObject);
	}
	
	/// <summary>
	/// Gets the name of the hovered window.
	/// </summary>
	/// <returns>
	/// The hovered window name.
	/// </returns>
	public static string GetHoveredWindowName()
	{
		Window hoveredWindow = GetHoveredWindow();
		if(hoveredWindow != null)
			return hoveredWindow.name;
		
		return null;
	}
	
	/// <summary>
	/// Gets the draged window.
	/// </summary>
	/// <returns>
	/// The draged window.
	/// </returns>
	public static Window GetDragedWindow()
	{
		GameObject dragedControl = GetDragedControl();
		if(dragedControl == null)
			return null;
		
		return NGUITools.FindInParents<Window>(dragedControl);
	}
	
	/// <summary>
	/// Gets the name of the draged window.
	/// </summary>
	/// <returns>
	/// The draged window name.
	/// </returns>
	public static string GetDragedWindowName()
	{
		Window window = GetDragedWindow();
		if(window == null)
			return null;
		
		return window.name;
	}
	#endregion //Window EventState	
	
	/// <summary>
	/// Gets the top second window.
	/// </summary>
	/// <returns>
	/// The top second window.
	/// </returns>
	public static Window GetTopSecondWindow()
	{
		int windowCount = openedSecondWindowList.Count;
		if(windowCount > 0)
			return openedSecondWindowList[windowCount - 1];
		
		return null;
	}
	
	/// <summary>
	/// Gets the name of the top second window.
	/// </summary>
	/// <returns>
	/// The top second window name.
	/// </returns>
	public static string GetTopSecondWindowName()
	{
		Window topSecondWindow = GetTopSecondWindow();
		if(topSecondWindow != null)
			return topSecondWindow.name;
		
		return null;
	}
	
	#endregion //Window
	
	#region //Panel
	
	
	#region //Panel Clipping
	/// <summary>
	/// 获取UI容器裁剪范围
	/// </summary>
	public static Vector4 GetPanelClipRange(string _panelName)
	{
		string windowName = _panelName.Split('_')[0];
        string panelName = _panelName.Substring(windowName.Length + 1);
		
		return GetPanelClipRange(GetControl(windowName, panelName));
	}
	
	/// <summary>
	/// 获取UI容器裁剪范围
	/// </summary>
	public static Vector4 GetPanelClipRange(string windowName, string panelName)
	{
		return GetPanelClipRange(GetControl(windowName, panelName));
	}
	
	/// <summary>
	/// 获取UI容器裁剪范围
	/// </summary>
	public static Vector4 GetPanelClipRange(Window window, string panelName)
	{
		return GetPanelClipRange(GetControl(window, panelName));
	}
	
	/// <summary>
	/// 获取UI容器裁剪范围
	/// </summary>
	public static Vector4 GetPanelClipRange(GameObject panelObj)
	{
		if(panelObj == null)
			return Vector4.zero;
		
		return GetPanelClipRange(panelObj.GetComponent<UIPanel>());
	}
	
	/// <summary>
	/// 获取UI容器裁剪范围
	/// </summary>
	public static Vector4 GetPanelClipRange(UIPanel panel)
	{
		if(panel != null)
			return panel.clipRange;
		
		return Vector4.zero;
	}
	
	/// <summary>
	/// 设置UI容器裁剪范围
	/// </summary>
	public static void SetPanelClipRange(string _panelName, Vector4 clipRange)
	{
		string windowName = _panelName.Split('_')[0];
        string panelName = _panelName.Substring(windowName.Length + 1);
		
		SetPanelClipRange(GetControl(windowName, _panelName), clipRange);
	}
	
	/// <summary>
	/// 设置UI容器裁剪范围
	/// </summary>
	public static void SetPanelClipRange(string windowName, string _panelName, Vector4 clipRange)
	{
		SetPanelClipRange(GetControl(windowName, _panelName), clipRange);
	}
	
	/// <summary>
	/// 设置UI容器裁剪范围
	/// </summary>
	public static void SetPanelClipRange(Window window, string _panelName, Vector4 clipRange)
	{
		SetPanelClipRange(GetControl(window, _panelName), clipRange);
	}
	
	/// <summary>
	/// 设置UI容器裁剪范围
	/// </summary>
	public static void SetPanelClipRange(GameObject panelObj, Vector4 clipRange)
	{
		SetPanelClipRange(panelObj.GetComponent<UIPanel>(), clipRange);
	}
	
	/// <summary>
	/// 设置UI容器裁剪范围
	/// </summary>
	public static void SetPanelClipRange(UIPanel panel, Vector4 clipRange)
	{
		if(panel == null)
			return;
		
		panel.clipRange = clipRange;
	}
	#endregion //Panel Clipping
		
		
	#endregion //Panel
	
	

    #region //Control Base

    #region //Control Instance
	/// <summary>
	///  获取窗口控件
	/// </summary>    
    public static GameObject GetControl(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
        return GetControl(GetWindow(windowName), controlName);
    }
	
	/// <summary>
	///  获取窗口控件
	/// </summary>    
    public static GameObject GetControl(string windowName, string controlName)
    {
        return GetControl(GetWindow(windowName), controlName);
    }
	
	/// <summary>
	///  获取窗口控件
	/// </summary> 
	public static GameObject GetControl(Window window, string controlName)
    {
		if(window == null)
			return null;
		
       	return GetControlInChildren(window.gameObject, controlName);
    }
	
	/// <summary>
	///  获取子控件
	/// </summary> 
	public static GameObject GetControlInChildren(GameObject obj, string controlName)
	{		
		if(obj == null)
			return null;

		Transform controlObj = null;
        string[] str = controlName.Split('/');
		Transform controlParentObj = obj.transform;
        for (int i = 0; i < str.Length; i++)
        {
            controlParentObj = GetControlInChildren(controlParentObj, str[i]);
            if (controlParentObj == null)
                return null;
			
			if(i == str.Length - 1)
             	controlObj = controlParentObj;
        }
		
		if(controlObj != null)
			return controlObj.gameObject;
		
		return null;
	}
	
	/// <summary>
	///  获取子控件
	/// </summary> 
    static Transform GetControlInChildren(Transform trans, string controlName)
    {	
		if(trans.name==controlName)
			return trans;
//		for(int i = 0; i < trans.childCount; i++)
//		{
//			Transform child = trans.GetChild(i);
//			if(child.gameObject.name == controlName)
//				return child;
//		}
		
		for(int i = 0; i < trans.childCount; i++)
		{
			Transform depChild = GetControlInChildren(trans.GetChild(i), controlName);
			if(depChild != null)
				return depChild;
		}
		
		return null;
    }
	
	/// <summary>
	/// 删除控件
	/// </summary>
	public void RemoveControl(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		RemoveControl(windowName, controlName);
	}
	
	/// <summary>
	/// 删除控件
	/// </summary>
	public void RemoveControl(string windowName, string controlName)
	{
		RemoveControl(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 删除控件
	/// </summary>
	public void RemoveControl(Window window, string controlName)
	{	
		RemoveControl(GetControl(window, controlName));
	}
	
	/// 删除控件
	/// </summary>
	public void RemoveControl(GameObject control)
	{
		DestroyImmediate(control);
	}
    #endregion  //Control Instance

    #region //Control Size
    /// <summary>
    /// 获取控件宽度
    /// </summary>
    public static float GetControlWidth(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlWidth(GetControl(windowName, controlName));		
    }
	
	/// <summary>
    /// 获取控件宽度
    /// </summary>
	public static float GetControlWidth(string windowName, string controlName)
	{
		return GetControlWidth(GetControl(windowName, controlName)); 		
	}
	
	/// <summary>
    /// 获取控件宽度
    /// </summary>
	public static float GetControlWidth(Window window, string controlName)
	{
		return GetControlWidth(GetControl(window, controlName)); 		
	}
	
	/// <summary>
    /// 获取控件宽度
    /// </summary>
	public static float GetControlWidth(GameObject control)
	{
		if(control == null)
			return 0;
		
		UILabel label = control.GetComponent<UILabel>();
		if(label != null)
			return label.pixelSize.x;
		
//		UIMix mix = control.GetComponent<UIMix>();
//		if(mix != null)
//			return mix.pixelSize.x;
		
		return control.transform.localScale.x;
	}

    /// <summary>
    /// 设置控件宽度
    /// </summary>
    public static void SetControlWidth(string _controlName, float width)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlWidth(GetControl(windowName, controlName), width);		
    }
	
	/// <summary>
    /// 设置控件宽度
    /// </summary>
	public static void SetControlWidth(string windowName, string controlName, float width)
    {
		SetControlWidth(GetControl(windowName, controlName), width);
	}
	
	/// <summary>
    /// 设置控件宽度
    /// </summary>
	public static void SetControlWidth(Window window, string controlName, float width)
    {
		SetControlWidth(GetControl(window, controlName), width);
	}
	
	/// <summary>
    /// 设置控件宽度
    /// </summary>
	public static void SetControlWidth(GameObject control, float width)
	{
		if(control == null)
			return;
		
		Vector3 scale = control.transform.localScale;
		control.transform.localScale = new Vector3(width, scale.y, scale.z);
	}

    /// <summary>
    /// 获取控件高度
    /// </summary>
    public static float GetControlHeight(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlHeight(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件高度
    /// </summary>
    public static float GetControlHeight(string windowName, string controlName)
    {
        return GetControlHeight(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件高度
    /// </summary>
    public static float GetControlHeight(Window window, string controlName)
    {
        return GetControlHeight(GetControl(window, controlName));
    }
	
	/// <summary>
    /// 获取控件高度
    /// </summary>
    public static float GetControlHeight(GameObject control)
    {
		if(control == null)
			return 0;
		
		return control.transform.localScale.y;
    }

    /// <summary>
    /// 设置控件高度
    /// </summary>
    public static void SetControlHeight(string _controlName, float height)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlHeight(GetControl(windowName, controlName), height);
    }
	
	/// <summary>
    /// 设置控件高度
    /// </summary>
    public static void SetControlHeight(string windowName, string controlName, float height)
    {
		SetControlHeight(GetControl(windowName, controlName), height);
	}
	
	/// <summary>
    /// 设置控件高度
    /// </summary>
    public static void SetControlHeight(Window window, string controlName, float height)
    {
		SetControlHeight(GetControl(window, controlName), height);
	}
	
	/// <summary>
    /// 设置控件高度
    /// </summary>
    public static void SetControlHeight(GameObject control, float height)
    {
		if(control == null)
			return;
		
		Vector3 scale = control.transform.localScale;
		control.transform.localScale = new Vector3(scale.x, height, scale.z);
	}

    /// <summary>
    /// 获取控件尺寸
    /// </summary>
    public static Vector3 GetControlSize(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlSize(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件尺寸
    /// </summary>
    public static Vector3 GetControlSize(string windowName, string controlName)
    {
        return GetControlSize(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件尺寸
    /// </summary>
    public static Vector3 GetControlSize(Window window, string controlName)
    {
        return GetControlSize(GetControl(window, controlName));
    }
	
	/// <summary>
    /// 获取控件尺寸
    /// </summary>
    public static Vector3 GetControlSize(GameObject control)
    {
        if(control == null)
			return Vector3.zero;
		
		bool normalNode = true;
		Vector3 controlSize = Vector3.zero;
		
		if(normalNode)
		{
			UILabel label = control.GetComponent<UILabel>();
			if(label != null)
			{
				normalNode = false;
				controlSize = label.pixelSize;
			}
		}
		
//		if(normalNode)
//		{
//			UIMix mix = control.GetComponent<UIMix>();
//			if(mix != null)
//			{
//				normalNode = false;
//				controlSize = mix.pixelSize;
//			}
//		}
		
		if(normalNode)
		{
			UISprite sprite = control.GetComponent<UISprite>();
			if(sprite != null)
			{
				normalNode = false;
				controlSize = control.transform.localScale;
			}
		}
		
		if(normalNode)
			controlSize = NGUIMath.CalculateRelativeWidgetBounds(control.transform).size;
		
		controlSize.x = Mathf.RoundToInt(controlSize.x);
		controlSize.y = Mathf.RoundToInt(controlSize.y);
		
		return controlSize;
    }

    /// <summary>
    /// 设置控件尺寸
    /// </summary>
    public static void SetControlSize(string _controlName, float width, float height)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlSize(GetControl(windowName, controlName), width, height);
    }
	
	/// <summary>
    /// 设置控件尺寸
    /// </summary>
    public static void SetControlSize(string windowName, string controlName, float width, float height)
    {
		SetControlSize(GetControl(windowName, controlName), width, height);
	}
	
	/// <summary>
    /// 设置控件尺寸
    /// </summary>
    public static void SetControlSize(Window window, string controlName, float width, float height)
    {
		SetControlSize(GetControl(window, controlName), width, height);
	}
	
	/// <summary>
    /// 设置控件尺寸
    /// </summary>
    public static void SetControlSize(GameObject control, float width, float height)
    {
		if(control == null)
			return;
		
		control.transform.localScale = new Vector3(width, height, control.transform.localScale.z);
	}
    #endregion //Control Size
	
	#region //Control Pivot
	/// <summary>
	/// 获取控件布局
	/// </summary>
	public static UIWidget.Pivot GetControlPivot(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlPivot(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件布局
	/// </summary>
	public static UIWidget.Pivot GetControlPivot(string windowName, string controlName)
	{
		return GetControlPivot(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件布局
	/// </summary>
	public static UIWidget.Pivot GetControlPivot(Window window, string controlName)
	{
		return GetControlPivot(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件布局
	/// </summary>
	public static UIWidget.Pivot GetControlPivot(GameObject control)
	{
		if(control == null)
			return UIWidget.Pivot.Center;
		
		UIWidget widget = control.GetComponent<UIWidget>();
		if(widget != null)
			return widget.pivot;
		
//		UIMix mix = control.GetComponent<UIMix>();
//		if(mix != null)
//			return mix.pivot;
		
		return UIWidget.Pivot.Center;
	}
	
	/// <summary>
	/// 设置控件布局
	/// </summary>
	public static void SetControlPivot(string _controlName, UIWidget.Pivot pivot)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlPivot(GetControl(windowName, controlName), pivot);
	}
	
	/// <summary>
	/// 设置控件布局
	/// </summary>
	public static void SetControlPivot(string windowName, string controlName, UIWidget.Pivot pivot)
	{
		SetControlPivot(GetControl(windowName, controlName), pivot);
	}
	
	/// <summary>
	/// 设置控件布局
	/// </summary>
	public static void SetControlPivot(Window window, string controlName, UIWidget.Pivot pivot)
	{
		SetControlPivot(GetControl(window, controlName), pivot);
	}
	
	/// <summary>
	/// 设置控件布局
	/// </summary>
	public static void SetControlPivot(GameObject control, UIWidget.Pivot pivot)
	{
		if(control == null)
			return;
		
		UIWidget widget = control.GetComponent<UIWidget>();
		if(widget != null)
		{
			widget.pivot = pivot;
			return;
		}
		
//		UIMix mix = control.GetComponent<UIMix>();
//		if(mix != null)
//		{
//			mix.pivot = pivot;
//			return;
//		}
	}
	#endregion //Control Pivot
	
	#region //Control pivotOffset
	public static Vector3 GetControlCenterPixelOffset(GameObject control)
	{
		if(control == null)
			return Vector3.zero;
		
		Vector3 offset = NGUIMath.CalculateRelativeWidgetBounds(control.transform).center;
		Transform trans = control.transform;
		if(trans.childCount > 0)
			return new Vector3( offset.x, -offset.y, offset.z);
		else
		{
			Vector3 size = trans.localScale;
			return new Vector3(offset.x * size.x, -(offset.y * size.y), offset.z * size.z);
		}
	}
	#endregion //Control offset

    #region //Control Position
	/// <summary>
    /// 获取控件X坐标
    /// </summary>
	public static float GetControlPositionX(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlPositionX(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件X坐标
    /// </summary>
	public static float GetControlPositionX(string windowName, string controlName)
	{
		return GetControlPositionX(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件X坐标
    /// </summary>
	public static float GetControlPositionX(Window window, string controlName)
	{
		return GetControlPositionX(GetControl(window, controlName));
	}
	
	/// <summary>
    /// 获取控件X坐标
    /// </summary>
	public static float GetControlPositionX(GameObject control)
	{
		if(control == null)
			return 0;
		
		return control.transform.localPosition.x;
	}
	
    /// <summary>
    /// 设置控件X坐标
    /// </summary>
    public static void SetControlPositionX(string _controlName, float posX)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlPositionX(GetControl(windowName, controlName), posX);
    }
	
	/// <summary>
    /// 设置控件X坐标
    /// </summary>
    public static void SetControlPositionX(string windowName, string controlName, float posX)
    {
        SetControlPositionX(GetControl(windowName, controlName), posX);
	}
	
	/// <summary>
    /// 设置控件X坐标
    /// </summary>
    public static void SetControlPositionX(Window window, string controlName, float posX)
    {
        SetControlPositionX(GetControl(window, controlName), posX);
	}
	
	/// <summary>
    /// 设置控件X坐标
    /// </summary>
    public static void SetControlPositionX(GameObject control, float posX)
    {
        if(control == null)
			return;
		
		posX = Mathf.RoundToInt(posX);
		Vector3 position = control.transform.localPosition;
		control.transform.localPosition = new Vector3(posX, position.y, position.z);
    }
	
	/// <summary>
    /// 获取控件Y坐标
    /// </summary>
	public static float GetControlPositionY(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlPositionY(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件Y坐标
    /// </summary>
	public static float GetControlPositionY(string windowName, string controlName)
	{
		return GetControlPositionY(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件Y坐标
    /// </summary>
	public static float GetControlPositionY(Window window, string controlName)
	{
		return GetControlPositionY(GetControl(window, controlName));
	}
	
	/// <summary>
    /// 获取控件Y坐标
    /// </summary>
	public static float GetControlPositionY(GameObject control)
	{
		if(control == null)
			return 0;
		
		return control.transform.localPosition.y;
	}
	
    /// <summary>
    /// 设置控件Y坐标
    /// </summary>
    public static void SetControlPositionY(string _controlName, float posY)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlPositionY(GetControl(windowName, controlName), posY);
    }
	
	/// <summary>
    /// 设置控件Y坐标
    /// </summary>
    public static void SetControlPositionY(string windowName, string controlName, float posY)
    {
		SetControlPositionY(GetControl(windowName, controlName), posY);
    }
	
	/// <summary>
    /// 设置控件Y坐标
    /// </summary>
    public static void SetControlPositionY(Window window, string controlName, float posY)
    {
		SetControlPositionY(GetControl(window, controlName), posY);
    }
	
	/// <summary>
    /// 设置控件Y坐标
    /// </summary>
    public static void SetControlPositionY(GameObject control, float posY)
    {
       if(control == null)
			return;
		
		Vector3 position = control.transform.localPosition;
		posY = Mathf.RoundToInt(posY);
		control.transform.localPosition = new Vector3(position.x, posY, position.z);
    }
	
	/// <summary>
    /// 获取控件Z坐标
    /// </summary>
	public static float GetControlPositionZ(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlPositionZ(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件Z坐标
    /// </summary>
	public static float GetControlPositionZ(string windowName, string controlName)
	{
		return GetControlPositionZ(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件Z坐标
    /// </summary>
	public static float GetControlPositionZ(Window window, string controlName)
	{
		return GetControlPositionZ(GetControl(window, controlName));
	}
	
	/// <summary>
    /// 获取控件Z坐标
    /// </summary>
	public static float GetControlPositionZ(GameObject control)
	{
		if(control == null)
			return 0;
		
		return control.transform.localPosition.z;
	}
	
    /// <summary>
    /// 设置控件Z坐标
    /// </summary>
    public static void SetControlPositionZ(string _controlName, float posZ)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlPositionZ(GetControl(windowName, controlName), posZ);
    }
	
	/// <summary>
    /// 设置控件Z坐标
    /// </summary>
    public static void SetControlPositionZ(string windowName, string controlName, float posZ)
    {
		SetControlPositionZ(GetControl(windowName, controlName), posZ);
    }
	
	/// <summary>
    /// 设置控件Z坐标
    /// </summary>
    public static void SetControlPositionZ(Window window, string controlName, float posZ)
    {
       SetControlPositionZ(GetControl(window, controlName), posZ);
    }
	
	/// <summary>
    /// 设置控件Z坐标
    /// </summary>
    public static void SetControlPositionZ(GameObject control, float posZ)
    {
       if(control == null)
			return;
		
		Vector3 position = control.transform.localPosition;
		control.transform.localPosition = new Vector3(position.x, position.y, posZ);
    }
	
	/// <summary>
    /// 获取控件坐标
    /// </summary>
	public static Vector3 GetControlPosition(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlPosition(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件坐标
    /// </summary>
	public static Vector3 GetControlPosition(string windowName, string controlName)
    {
        return GetControlPosition(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件坐标
    /// </summary>
	public static Vector3 GetControlPosition(Window window, string controlName)
    {
        return GetControlPosition(GetControl(window, controlName));
    }
	
	/// <summary>
    /// 获取控件坐标
    /// </summary>
	public static Vector3 GetControlPosition(GameObject control)
    {
        if(control == null)
			return Vector3.zero;
		
		return control.transform.localPosition;
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(string _controlName, float posX, float posY)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

		SetControlPosition(GetControl(windowName, controlName), posX, posY);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(string windowNmae, string controlName, float posX, float posY)
    {
		SetControlPosition(GetControl(windowNmae, controlName), posX, posY);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(Window window, string controlName, float posX, float posY)
    {
		SetControlPosition(GetControl(window, controlName), posX, posY);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(GameObject control, float posX, float posY)
    {
        if(control == null)
			return;
		
		posX = Mathf.RoundToInt(posX);
		posY = Mathf.RoundToInt(posY);
		
		control.transform.localPosition = new Vector3(posX, posY, control.transform.localPosition.z);
    }

    /// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(string _controlName, float posX, float posY, float posZ)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

		SetControlPosition(GetControl(windowName, controlName), posX, posY, posZ);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(string windowNmae, string controlName, float posX, float posY, float posZ)
    {
		SetControlPosition(GetControl(windowNmae, controlName), posX, posY, posZ);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(Window window, string controlName, float posX, float posY, float posZ)
    {
		SetControlPosition(GetControl(window, controlName), posX, posY, posZ);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(GameObject control, float posX, float posY, float posZ)
    {
        if(control == null)
			return;
		
		posX = Mathf.RoundToInt(posX);
		posY = Mathf.RoundToInt(posY);
		
		control.transform.localPosition = new Vector3(posX, posY, posZ);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(string _controlName, Vector3 pos)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

		SetControlPosition(GetControl(windowName, controlName), pos);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(string windowNmae, string controlName, Vector3 pos)
    {
		SetControlPosition(GetControl(windowNmae, controlName), pos);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(Window window, string controlName, Vector3 pos)
    {
		SetControlPosition(GetControl(window, controlName), pos);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(GameObject control, Vector3 pos)
    {
        if(control == null)
			return;
		
		pos.x = Mathf.RoundToInt(pos.x);
		pos.y = Mathf.RoundToInt(pos.y);
		
		control.transform.localPosition = pos;
    }
    #endregion //Control Position

    #region //Control Sprite And Resources
    /// <summary>
    /// 获取控件SpriteName
    /// </summary>
    public static string GetControlSpriteName(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlSpriteName(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件SpriteName
    /// </summary>
    public static string GetControlSpriteName(string windowName, string controlName)
    {
		return GetControlSpriteName(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件SpriteName
    /// </summary>
    public static string GetControlSpriteName(Window window, string controlName)
    {
		return GetControlSpriteName(GetControl(window, controlName));
    }
	
	/// <summary>
    /// 获取控件SpriteName
    /// </summary>
    public static string GetControlSpriteName(GameObject control)
    {
		if(control == null)
			return null;
		
        UISprite sprite = control.GetComponent<UISprite>();
		if(sprite == null)
			return null;
		
		return sprite.spriteName;
    }
	
	/// <summary>
    /// 设置控件SpriteName
    /// </summary>
	public static void SetControlSpriteName(string _controlName, string spriteName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlSpriteName(GetControl(windowName, controlName), spriteName);
    }
	
	/// <summary>
    /// 设置控件SpriteName
    /// </summary>
	public static void SetControlSpriteName(string windowName, string controlName, string spriteName)
    {
        SetControlSpriteName(GetControl(windowName, controlName), spriteName);
    }
	
	/// <summary>
    /// 设置控件SpriteName
    /// </summary>
	public static void SetControlSpriteName(Window window, string controlName, string spriteName)
    {
        SetControlSpriteName(GetControl(window, controlName), spriteName);
    }
	
	/// <summary>
    /// 设置控件SpriteName
    /// </summary>
	public static void SetControlSpriteName(GameObject control, string spriteName)
    {
        if(control == null)
			return;
		
		UISprite sprite = control.GetComponent<UISprite>();
		if(sprite == null)
			return;
		
		sprite.spriteName = spriteName;
    }
	
	/// <summary>
	/// 获取控件资源图片集名字
	/// </summary>
	public static string GetControlAtlasName(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlAtlasName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件资源图片集名字
	/// </summary>
	public static string GetControlAtlasName(string windowName, string controlName)
	{
		return GetControlAtlasName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件资源图片集名字
	/// </summary>
	public static string GetControlAtlasName(Window window, string controlName)
	{
		return GetControlAtlasName(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件资源图片集名字
	/// </summary>
	public static string GetControlAtlasName(GameObject control)
	{
		UIAtlas atlas = GetControlAtlas(control);
		if(atlas == null)
			return null;
		
		return atlas.name;
	}
	
	/// <summary>
	/// 获取控件资源图片集
	/// </summary>
	public static UIAtlas GetControlAtlas(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlAtlas(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件资源图片集
	/// </summary>
	public static UIAtlas GetControlAtlas(string windowName, string controlName)
	{
		return GetControlAtlas(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件资源图片集
	/// </summary>
	public static UIAtlas GetControlAtlas(Window window, string controlName)
	{
		return GetControlAtlas(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件资源图片集
	/// </summary>
	public static UIAtlas GetControlAtlas(GameObject control)
	{
		if(control == null)
			return null;
		
		UISprite sprite = control.GetComponent<UISprite>();
		if(sprite == null)
			return null;
		
		return sprite.atlas;
	}
	
	/// <summary>
    /// 设置控件资源图片集
    /// </summary>
    public static void SetControlAtlas(string _controlName, UIAtlas atlas)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
        SetControlAtlas(GetControl(windowName, controlName), atlas);
    }
	
	/// <summary>
    /// 设置控件资源图片集
    /// </summary>
    public static void SetControlAtlas(string windowName, string controlName, UIAtlas atlas)
    {
       SetControlAtlas(GetControl(windowName, controlName), atlas);
    }
	
	/// <summary>
    /// 设置控件资源图片集
    /// </summary>
    public static void SetControlAtlas(Window window, string controlName, UIAtlas atlas)
    {
       SetControlAtlas(GetControl(window, controlName), atlas);
    }
	
	/// <summary>
    /// 设置控件资源图片集
    /// </summary>
    public static void SetControlAtlas(GameObject control, UIAtlas atlas)
    {
       if(control == null)
			return;
		
		UISprite sprite = control.GetComponent<UISprite>();
		if(sprite == null)
			return;
		
		sprite.atlas = atlas;
    }
	
	/// <summary>
	/// 获取控件材质球名字
	/// </summary>
	public static string GetControlMaterialName(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlMaterialName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件材质球名字
	/// </summary>
	public static string GetControlMaterialName(string windowName, string controlName)
	{
		return GetControlMaterialName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件材质球名字
	/// </summary>
	public static string GetControlMaterialName(Window window, string controlName)
	{
		return GetControlMaterialName(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件材质球名字
	/// </summary>
	public static string GetControlMaterialName(GameObject control)
	{
		Material material = GetControlMaterial(control);
		if(material == null)
			return null;
		
		return material.name;
	}
	
	/// <summary>
	/// 获取控件材质球
	/// </summary>
	public static Material GetControlMaterial(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlMaterial(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件材质球
	/// </summary>
	public static Material GetControlMaterial(string windowName, string controlName)
	{
		return GetControlMaterial(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件材质球
	/// </summary>
	public static Material GetControlMaterial(Window window, string controlName)
	{
		return GetControlMaterial(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件材质球
	/// </summary>
	public static Material GetControlMaterial(GameObject control)
	{
		if(control == null)
			return null;

		UIWidget widget = control.GetComponent<UIWidget>();
		if(widget == null)
			return null;
		
		return widget.material;
	}
	
	/// <summary>
	/// 设置控件材质球
	/// </summary>
	public static void SetControlMaterial(string _controlName, Material material)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlMaterial(GetControl(windowName, controlName), material);
	}
	
	/// <summary>
	/// 设置控件材质球
	/// </summary>
	public static void SetControlMaterial(string windowName, string controlName, Material material)
	{
		SetControlMaterial(GetControl(windowName, controlName), material);
	}
	
	/// <summary>
	/// 设置控件材质球
	/// </summary>
	public static void SetControlMaterial(Window window, string controlName, Material material)
	{
		SetControlMaterial(GetControl(window, controlName), material);
	}
	
	/// <summary>
	/// 设置控件材质球
	/// </summary>
	public static void SetControlMaterial(GameObject control, Material material)
	{
		if(control == null)
			return;
		
		UIWidget widget = control.GetComponent<UIWidget>();
		if(widget == null)
			return;
		
		widget.material = material;
	}
    #endregion  //Control Sprite And Resources

    #region //Control Color	
    /// <summary>
    /// 设置控件颜色
    /// </summary>
    public static void SetControlColor(string _controlName, Color color)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlColor(GetControl(windowName, controlName), color);
    }
	
	/// <summary>
    /// 设置控件颜色
    /// </summary>
    public static void SetControlColor(string windowName, string controlNanme, Color color)
    {
        SetControlColor(GetControl(windowName, controlNanme), color);
    }
	
	/// <summary>
    /// 设置控件颜色
    /// </summary>
    public static void SetControlColor(Window window, string controlNanme, Color color)
    {
        SetControlColor(GetControl(window, controlNanme), color);
    }
	
	/// <summary>
    /// 设置控件颜色
    /// </summary>
    public static void SetControlColor(GameObject control, Color color)
    {
        if(control == null)
			return;
		
		UIWidget widget = control.GetComponent<UIWidget>();
		if(widget != null)
			widget.color = color;
//		else
//		{
//			UIMix mix = control.GetComponent<UIMix>();
//			if(mix != null)
//				mix.color = color;
//		}
    }

    /// <summary>
    /// 设置控件透明度
    /// </summary>
    public static void SetControlAlpha(string _controlName, float alpha, bool toChildren)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

       	SetControlAlpha(GetControl(windowName, controlName), alpha, toChildren);
    }
	
	/// <summary>
	/// 设置控件透明度
	/// </summary>
	public static void SetControlAlpha(string windowName, string controlName, float alpha, bool toChildren)
	{
		SetControlAlpha(GetControl(windowName, controlName), alpha, toChildren);
	}
	
	/// <summary>
	/// 设置控件透明度
	/// </summary>
	public static void SetControlAlpha(Window window, string controlName, float alpha, bool toChildren)
	{
		SetControlAlpha(GetControl(window, controlName), alpha, toChildren);
	}
	
	/// <summary>
	/// 设置控件透明度
	/// </summary>
	public static void SetControlAlpha(GameObject control, float alpha, bool toChildren)
	{
		if(control == null)
			return;
		
		SetControlAlpha(control.transform, alpha, toChildren);
	}
	
	//设置控件透明度
	public static void SetControlAlpha(Transform trans, float alpha, bool toChildren)
	{
		SetControlAlpha(trans, alpha, toChildren, false);
	}
	
	//设置控件透明度
	public static void SetControlAlpha(Transform trans, float alpha, bool toChildren, bool windowAlpha)
	{
		UIWidget widget = trans.GetComponent<UIWidget>();
		if(widget != null)
		{			
			UIAlaphaTweenRecord record = trans.GetComponent<UIAlaphaTweenRecord>();
			
			if(!windowAlpha || record == null)
				widget.alpha = alpha;
			else
				widget.alpha = record.oldAlpha * alpha;
			
			if(widget is UILabel)
			{
				UILabel label = widget as UILabel;
				if(label.effectStyle != UILabel.Effect.None)
				{
					Color effectColor = label.effectColor;
					if(!windowAlpha || record == null)
						effectColor.a = alpha;
					else
						effectColor.a = record.effectColor.a * alpha;
					
					label.effectColor = effectColor;
				}
			}
		}
		
//		UIMix mix = trans.GetComponent<UIMix>();
//		if(mix != null)
//		{
//			toChildren = false;
//			
//			UIAlaphaTweenRecord record = trans.GetComponent<UIAlaphaTweenRecord>();
//			if(!windowAlpha || record == null)
//				mix.alpha = alpha;
//			else
//				mix.alpha = record.oldAlpha * alpha;
//			
//			if(mix.effectStyle != UILabel.Effect.None)
//			{
//				Color effectColor = mix.effectColor;
//				if(!windowAlpha || record == null)
//					effectColor.a = alpha;
//				else
//					effectColor.a = record.effectColor.a * alpha;
//				mix.effectColor = effectColor;
//			}
//		}
		
		if(toChildren)
		{
			for(int i = 0; i < trans.childCount; i++)
				SetControlAlpha(trans.GetChild(i), alpha, toChildren);
		}
	}
		
	//记录控件默认透明度
	public static void RecordAlpha(Transform trans)
	{
		UIWidget widget = trans.GetComponent<UIWidget>();
		if(widget != null)
		{			
			UIAlaphaTweenRecord record = trans.GetComponent<UIAlaphaTweenRecord>();
			if(record == null)
				record = trans.gameObject.AddComponent<UIAlaphaTweenRecord>();
				
			record.oldAlpha = widget.alpha;				
			if(widget is UILabel)
			{
				UILabel label = widget as UILabel;
				if(label.effectStyle != UILabel.Effect.None)
				{
					record.effectStyle = label.effectStyle;
					record.effectColor = label.effectColor;
				}
			}
		}
		
//		UIMix mix = trans.GetComponent<UIMix>();
//		if(mix != null)
//		{
//			UIAlaphaTweenRecord record = trans.GetComponent<UIAlaphaTweenRecord>();
//			if(record == null)
//				record = trans.gameObject.AddComponent<UIAlaphaTweenRecord>();
//			
//			record.oldAlpha = mix.alpha;
//			
//			if(mix.effectStyle != UILabel.Effect.None)
//			{
//				record.effectStyle = mix.effectStyle;
//				record.effectColor = mix.effectColor;
//			}
//		}
		
		for(int i = 0; i < trans.childCount; i++)
			RecordAlpha(trans.GetChild(i));;
	}
	
	//恢复控件默认透明度
	public static void RevertAlpha(Transform trans)
	{
		UIWidget widget = trans.GetComponent<UIWidget>();
		if(widget != null)
		{
			UIAlaphaTweenRecord record = trans.GetComponent<UIAlaphaTweenRecord>();
			if(record != null)
			{
				widget.alpha = record.oldAlpha;
			
				if(widget is UILabel)
				{
					UILabel label = widget as UILabel;
					if(label.effectStyle != UILabel.Effect.None)
					{
						label.effectStyle = record.effectStyle;
						label.effectColor = record.effectColor;
					}
				}
			}
		}
		
//		UIMix mix = trans.GetComponent<UIMix>();
//		if(mix != null)
//		{
//			UIAlaphaTweenRecord record = trans.GetComponent<UIAlaphaTweenRecord>();
//			if(record != null)
//			{
//				if(mix.effectStyle != UILabel.Effect.None)
//				{
//					mix.alpha = record.oldAlpha;
//					mix.effectStyle = record.effectStyle;
//					mix.effectColor = record.effectColor;
//				}
//			}
//		}
		
		for(int i = 0; i < trans.childCount; i++)
			RevertAlpha(trans.GetChild(i));
	}
    #endregion  //Control Color
	
	#region //Control Normal
	/// <summary>
	/// 检测控件是否为正常状态
	/// </summary>
	public static bool IsControlNormalState(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return IsControlNormalState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件状态是否为正常状态
	/// </summary>
	public static bool IsControlNormalState(string windowName, string controlName)
	{
		return IsControlNormalState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件状态是否为正常状态
	/// </summary>
	public static bool IsControlNormalState(Window window, string controlName)
	{
		return IsControlNormalState(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件状态是否为正常状态
	/// </summary>
	public static bool IsControlNormalState(GameObject control)
	{
		if(control == null)
			return false;
		
		if(IsControlHoveredState(control))
			return false;
		if(IsControlDragedState(control))
			return false;
		if(IsControlPressedState(control))
			return false;
		if(IsControlSelectedState(control))
			return false;
		
		//Checked
		if(IsControlCheckedState(control))
			return false;
		
		return true;
	}
	
	/// <summary>
	/// 设置控件状态为正常状态
	/// </summary>
	public static void SetControlStateToNormal(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlStateToNormal(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 设置控件状态为正常状态
	/// </summary>
	public static void SetControlStateToNormal(string windowName, string contorlName)
	{
		SetControlStateToNormal(GetControl(windowName, contorlName));
	}
	
	/// <summary>
	/// 设置控件状态为正常状态
	/// </summary>
	public static void SetControlStateToNormal(Window window, string contorlName)
	{
		SetControlStateToNormal(GetControl(window, contorlName));
	}
	
	/// <summary>
	/// 设置控件状态为正常状态
	/// </summary>
	public static void SetControlStateToNormal(GameObject contorl)
	{
		if(contorl == null)
			return;
		
		//Hover & Drag can't notify.

		SetControlPresseState(contorl, false);
		
		SetControlSelectState(contorl, false);
		
		//Checked
		SetControlCheckState(contorl, false);
		
		UIImageButton umb = contorl.GetComponent<UIImageButton>();
		if(umb != null)
		{
			if(umb.target != null)
				umb.target.spriteName = umb.normalSprite;
		}
	}
	#endregion //Control Normal
	
	#region //Control Hover
	/// <summary>
	/// 获取当前被鼠标悬停的控件
	/// </summary>
	public static GameObject GetHoveredControl()
	{
		return UICamera.hoveredObject;
	}
	
	/// <summary>
	/// 获取当前被鼠标悬停的控件的名字
	/// </summary>
	public static string GetHoveredControlName()
	{
		GameObject hoveredObject = GetHoveredControl();
		if(hoveredObject != null)
			return hoveredObject.name;
		
		return null;
	}
	
	/// <summary>
	/// 检测控件是否为被鼠标悬停状态
	/// </summary>
	public static bool IsControlHoveredState(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return IsControlHoveredState(GetControl(windowName, controlName));
    }
	
	/// <summary>
	/// 检测控件是否为被鼠标悬停状态
	/// </summary>
	public static bool IsControlHoveredState(string windowName, string controlName)
    {
       return IsControlHoveredState(GetControl(windowName, controlName));
    }
	
	/// <summary>
	/// 检测控件是否为被鼠标悬停状态
	/// </summary>
	public static bool IsControlHoveredState(Window window, string controlName)
    {
       return IsControlHoveredState(GetControl(window, controlName));
    }
	
	/// <summary>
	/// 检测控件是否为被鼠标悬停状态
	/// </summary>
	public static bool IsControlHoveredState(GameObject control)
    {
		if(control == null)
			return false;
		
       	return (control == GetHoveredControl());
    }
	#endregion //Control Hover
	
	#region //Control Drag
	/// <summary>
	/// 获取正被鼠标Draed的控件
	/// </summary>
	public static GameObject GetDragedControl()
	{
		return UICamera.dragedObject;
	}
	
	/// <summary>
	/// 获取正被鼠标Draed的控件
	/// </summary>
	public static string GetDragedControlName()
	{
		GameObject dragedObject = GetDragedControl();
		if(dragedObject == null)
			return null;
		
		return dragedObject.name;
	}
	
	/// <summary>
	/// 检测控件是否为被Draged状态
	/// </summary>
	public static bool IsControlDragedState(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return IsControlDragedState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为被Draged状态
	/// </summary>
	public static bool IsControlDragedState(string windowName, string controlName)
	{
		return IsControlDragedState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为被Draged状态
	/// </summary>
	public static bool IsControlDragedState(Window window, string controlName)
	{
		return IsControlDragedState(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为被Draged状态
	/// </summary>
	public static bool IsControlDragedState(GameObject control)
	{
		if(control == null)
			return false;
		
		return (control == GetDragedControl());
	}
	#endregion //Control Drag
	
	#region //Control Press
	/// <summary>
	/// 获取当前被鼠标按下的控件
	/// </summary>
	public static GameObject GetPressedControl()
	{
		return UICamera.pressedObject;
	}
	
	/// <summary>
	/// 获取当前被鼠标按下的控件的名字
	/// </summary>
	public static string GetPressedControlName()
	{
		GameObject pressedObject = UICamera.pressedObject;
		if(pressedObject == null)
			return null;
		
		return pressedObject.name;
	}
	
	/// <summary>
	/// 检测控件是否为鼠标按下状态
	/// </summary>
	public static bool IsControlPressedState(string _controlName)
	{		
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return IsControlPressedState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为鼠标按下状态
	/// </summary>
	public static bool IsControlPressedState(string windowName, string controlName)
	{
		return IsControlPressedState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为鼠标按下状态
	/// </summary>
	public static bool IsControlPressedState(Window window, string controlName)
	{
		return IsControlPressedState(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为鼠标按下状态
	/// </summary>
	public static bool IsControlPressedState(GameObject control)
	{
		if(control == null)
			return false;
		
		return (control == GetPressedControl());
	}
	
	/// <summary>
	/// 设置控件为按下状态
	/// </summary>
	public static void SetControlPresseState(string _controlName, bool state)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlPresseState(GetControl(windowName, controlName), state);
	}
	
	/// <summary>
	/// 设置控件为按下状态
	/// </summary>
	public static void SetControlPresseState(string windowName, string controlName, bool state)
	{
		SetControlPresseState(GetControl(windowName, controlName), state);
	}
	
	/// <summary>
	/// 设置控件为按下状态
	/// </summary>
	public static void SetControlPresseState(Window window, string controlName, bool state)
	{
		SetControlPresseState(GetControl(window, controlName), state);
	}
	
	/// <summary>
	/// 设置控件为按下状态
	/// </summary>
	public static void SetControlPresseState(GameObject control, bool state)
	{
		if(control == null)
			return;
		
		if(state)
			UICamera.pressedObject = control;
		else if(UICamera.pressedObject == control)
			UICamera.pressedObject = null;
	}
	
	/// <summary>
	/// 获取Group中被鼠标按下对象的序号
	/// </summary>
	public static int GetGroupControlPressedIndex(string _controlName)
	{				
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

 		return GetGroupControlPressedIndex(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取Group中被鼠标按下对象的序号
	/// </summary>
	public static int GetGroupControlPressedIndex(string windowName, string controlName)
	{
		return GetGroupControlPressedIndex(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取Group中被鼠标按下对象的序号
	/// </summary>
	public static int GetGroupControlPressedIndex(Window window, string controlName)
	{
		return GetGroupControlPressedIndex(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取Group中被鼠标按下对象的序号
	/// </summary>
	public static int GetGroupControlPressedIndex(GameObject control)
	{
		if(control == null)
			return -1;
		
		GameObject pressedObject = GetPressedControl();
		if(pressedObject == null)
			return -1;
		
		UITable table = control.GetComponent<UITable>();
		if(table != null)
		{
			for(int i = 0; i < table.children.Count; i++)
			{
				if(NGUITools.IsChild(table.children[i], pressedObject.transform))
					return i;
			}
		}
		
		for(int i = 0; i < control.transform.childCount; i++)
		{
			if(pressedObject.transform.IsChildOf(control.transform.GetChild(i)))
				return i;
		}
		
		return -1;
	}
	
	/// <summary>
	/// 设置Group中被鼠标按下对象的序号
	/// </summary>
	public static void SetGroupControlPressedIndex(string _controlName, int index)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetGroupControlPressedIndex(GetControl(windowName, controlName), index);
	}
	
	/// <summary>
	/// 设置Group中被鼠标按下对象的序号
	/// </summary>
	public static void SetGroupControlPressedIndex(string windowName, string controlName, int index)
	{
		SetGroupControlPressedIndex(GetControl(windowName, controlName), index);
	}
	
	/// <summary>
	/// 设置Group中被鼠标按下对象的序号
	/// </summary>
	public static void SetGroupControlPressedIndex(Window window, string controlName, int index)
	{
		SetGroupControlPressedIndex(GetControl(window, controlName), index);
	}
	
	/// <summary>
	/// 设置Group中被鼠标按下对象的序号
	/// </summary>
	public static void SetGroupControlPressedIndex(GameObject control, int index)
	{
		if(control == null)
			return;
		
		Transform pressedObject = null;
		
		UITable table = control.GetComponent<UITable>();
		if(table != null)		
		{
			if(index >= 0 && index < table.children.Count)
				pressedObject = table.children[index];
		}
		else if(index >= 0 && index < control.transform.childCount)
			pressedObject = control.transform.GetChild(index);
		
		if(pressedObject != null)
			SetControlPresseState(pressedObject.gameObject, true);
	}

	#endregion //Control Press
	
    #region //Control Select
	/// <summary>
	/// 获取当前被鼠标选中的控件
	/// </summary>
	public static GameObject GetSelectedControl()
	{
		return UICamera.selectedObject;
	}
	
    /// <summary>
    /// 获取当前被鼠标选中的控件的对象
    /// </summary>
    public static string GetSelectedControlName()
    {
        GameObject selectedObject = UICamera.selectedObject;
		if(selectedObject == null)
			return null;
		
		return selectedObject.name;
    }
	
	/// <summary>
    /// 检测控件是否为被鼠标选中状态
    /// </summary>
    public static bool IsControlSelectedState(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return IsControlSelectedState(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 检测控件是否为被鼠标选中状态
    /// </summary>
    public static bool IsControlSelectedState(string windowName, string controlName)
    {
		return IsControlSelectedState(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 检测控件是否为被鼠标选中状态
    /// </summary>
    public static bool IsControlSelectedState(Window window, string controlName)
    {
		return IsControlSelectedState(GetControl(window, controlName));
    }

    /// <summary>
    /// 检测控件是否为被鼠标选中状态
    /// </summary>
    public static bool IsControlSelectedState(GameObject control)
    {
		if(control == null)
			return false;
		
		return (control == GetSelectedControl());
    }

    /// <summary>
    /// 设置控件的选中状态
    /// </summary>
    public static void SetControlSelectState(string _controlName, bool state)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlSelectState(GetControl(windowName, controlName), state);
    }
	
	/// <summary>
    /// 设置控件的选中状态
    /// </summary>
    public static void SetControlSelectState(string windowName, string controlName, bool state)
    {
		SetControlSelectState(GetControl(windowName, controlName), state);
    }
	
	/// <summary>
    /// 设置控件的选中状态
    /// </summary>
    public static void SetControlSelectState(Window window, string controlName, bool state)
    {
		SetControlSelectState(GetControl(window, controlName), state);
    }
	
	/// <summary>
    /// 设置控件的选中状态
    /// </summary>
    public static void SetControlSelectState(GameObject control, bool state)
    {
		if(control == null)
			return;

		UIImageButton umb = control.GetComponent<UIImageButton>();
		if(state)
		{
			UICamera.selectedObject = control;  
			
			if(umb != null)
			{
				if(umb.target != null)
					umb.target.spriteName = umb.hoverSprite;
				
				umb.GetComponent<BoxCollider>().enabled = false;
			}
		}
		else if(UICamera.selectedObject == control)
		{
			UICamera.selectedObject = null;
			if(umb != null)
			{
				if(umb.target != null)
					umb.target.spriteName = umb.normalSprite;
				
				umb.GetComponent<BoxCollider>().enabled = true;
			}
		}
    }
	
	/// <summary>
	/// 获取Group中被选中对象的序号
	/// </summary>
	public static int GetGroupControlSelectedIndex(string _controlName)
	{				
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

 		return GetGroupControlSelectedIndex(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取Group中被选中对象的序号
	/// </summary>
	public static int GetGroupControlSelectedIndex(string windowName, string controlName)
	{
		return GetGroupControlSelectedIndex(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取Group中被选中对象的序号
	/// </summary>
	public static int GetGroupControlSelectedIndex(Window window, string controlName)
	{
		return GetGroupControlSelectedIndex(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取Group中被选中对象的序号
	/// </summary>
	public static int GetGroupControlSelectedIndex(GameObject control)
	{
		if(control == null)
			return -1;
		
		GameObject selectedObject = GetSelectedControl();
		if(selectedObject == null)
			return -1;
		
		UITable table = control.GetComponent<UITable>();
		if(table != null)
		{
			for(int i = 0; i < table.children.Count; i++)
			{
				if(NGUITools.IsChild(table.children[i], selectedObject.transform))
					return i;
			}
		}
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
		{
			for(int i = 0; i < list.items.Count; i++)
			{
				if(list.selection == list.items[i])
					return i;
			}
		}
		
		for(int i = 0; i < control.transform.childCount; i++)
		{
			if(selectedObject.transform.IsChildOf(control.transform.GetChild(i)))
				return i;
		}
		
		return -1;
	}
	
	/// <summary>
	/// 设置Group中被选中对象的序号
	/// </summary>
	public static void SetGroupControlSelectedIndex(string _controlName, int index)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetGroupControlSelectedIndex(GetControl(windowName, controlName), index);
	}
	
	/// <summary>
	/// 设置Group中被选中对象的序号
	/// </summary>
	public static void SetGroupControlSelectedIndex(string windowName, string controlName, int index)
	{
		SetGroupControlSelectedIndex(GetControl(windowName, controlName), index);
	}
	
	/// <summary>
	/// 设置Group中被选中对象的序号
	/// </summary>
	public static void SetGroupControlSelectedIndex(Window window, string controlName, int index)
	{
		SetGroupControlSelectedIndex(GetControl(window, controlName), index);
	}
	
	/// <summary>
	/// 设置Group中被选中对象的序号
	/// </summary>
	public static void SetGroupControlSelectedIndex(GameObject control, int index)
	{
		if(control == null)
			return;
		
		Transform selectedObject = null;		
		UITable table = control.GetComponent<UITable>();
		if(table != null)
		{
			if(index >= 0 && index < table.children.Count)
				selectedObject = table.children[index];	
			
			if(selectedObject != null)
			{
				SetControlSelectState(selectedObject.gameObject, true);
				return;
			}
		}
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
		{
			if(index >= 0 && index < list.items.Count)
			{
				list.selection = list.items[index];
				return;
			}
		}

		if(index >= 0 && index < control.transform.childCount)
		{
			selectedObject = control.transform.GetChild(index);		
			if(selectedObject != null)
			{
				SetControlSelectState(selectedObject.gameObject, true);
				return;
			}			
		}
	}
	
	/// <summary>
	/// 设置下拉列表的选项内容
	/// </summary>
	public static void SetControlItemList(GameObject control, List<string> items)
	{
		if(control == null)
			return;
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list == null)
			return;
		
		list.items = items;
		if(items.Count > 0)
			list.selection = items[0];
	}
    #endregion  //Control Select
	
	#region //Control Checked
	/// <summary>
	/// 检测控件是否为被Checked状态
	/// </summary>
	public static bool IsControlCheckedState(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return IsControlCheckedState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为被Checked状态
	/// </summary>
	public static bool IsControlCheckedState(string windowName, string controlName)
	{
		return IsControlCheckedState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为被Checked状态
	/// </summary>
	public static bool IsControlCheckedState(Window window, string controlName)
	{
		return IsControlCheckedState(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为被Checked状态
	/// </summary>
	public static bool IsControlCheckedState(GameObject control)
	{
		if(control == null)
			return false;
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
			return checkbox.isChecked;
		
		return false;
	}
	
	/// <summary>
	/// 设置控件状态为被Checked状态
	/// </summary>>
	public static void SetControlCheckState(string _controlName, bool state)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlCheckState(GetControl(windowName, controlName), state);
	}	
	
	/// <summary>
	/// 设置控件状态为被Checked状态
	/// </summary>
	public static void SetControlCheckState(string windowName, string controlName, bool state)
	{
		SetControlCheckState(GetControl(windowName, controlName), state);
	}
	
	/// <summary>
	/// 设置控件状态为被Checked状态
	/// </summary>
	public static void SetControlCheckState(Window window, string controlName, bool state)
	{
		SetControlCheckState(GetControl(window, controlName), state);
	}
	
	/// <summary>
	/// 设置控件状态为被Checked状态
	/// </summary>
	public static void SetControlCheckState(GameObject control, bool state)
	{
		if(control == null)
			return;
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox == null)
			return;
		
		checkbox.isChecked = state;
	}
	#endregion //Control Checked
	
	#region //Control Visible
    /// <summary>
    /// 检测控件是否为可视状态
    /// </summary>
    public static bool IsControlVisible(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return IsControlVisible(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 检测控件是否为可视状态
    /// </summary>
    public static bool IsControlVisible(string windowName, string controlName)
    {
        return IsControlVisible(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 检测控件是否为可视状态
    /// </summary>
    public static bool IsControlVisible(Window window, string controlName)
    {
        return IsControlVisible(GetControl(window, controlName));
    }
	
	/// <summary>
    /// 检测控件是否为可视状态
    /// </summary>
    public static bool IsControlVisible(GameObject control)
    {
        if(control == null)
			return false;
		
        return control.gameObject.active;
    }

    /// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(string _controlName, bool Visible)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

       	SetControlVisible(GetControl(windowName, controlName), Visible, true);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(string _controlName, bool Visible, bool toChildren)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

       	SetControlVisible(GetControl(windowName, controlName), Visible, toChildren);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(string windowName, string controlName, bool Visible)
    {
        SetControlVisible(GetControl(windowName, controlName), Visible, true);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(string windowName, string controlName, bool Visible, bool toChildren)
    {
        SetControlVisible(GetControl(windowName, controlName), Visible, toChildren);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(Window window, string controlName, bool Visible)
    {
        SetControlVisible(GetControl(window, controlName), Visible, true);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(Window window, string controlName, bool Visible, bool toChildren)
    {
        SetControlVisible(GetControl(window, controlName), Visible, toChildren);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(GameObject control, bool Visible)
    {
        SetControlVisible(control, Visible, true);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(GameObject control, bool Visible, bool toChildren)
    {
        if(control == null)
			return;
		
		//隐藏前先刷新默认隐藏对象
//		UIDefaultHideChildren[] hides = control.GetComponentsInChildren<UIDefaultHideChildren>();
//		if(!Visible && toChildren)
//		{
//			foreach(UIDefaultHideChildren hide in hides)
//				hide.RefreshDefaultHideChildren();			
//		}
		
		if(toChildren)
			control.gameObject.SetActiveRecursively(Visible);
		else
			control.gameObject.active = Visible;
		
		//显示后隐藏默认隐藏对象
//		if(Visible && toChildren)
//		{			
//			foreach(UIDefaultHideChildren hide in hides)
//				hide.HideDefaultHideChildren();
//		}
    }
    #endregion  // Control Visible
	
	#region //Control Collider
	/// <summary>
	/// 设置控件的碰撞属性状态
	/// </summary>
	public static void SetControlColliderEnabled(string _controlName, bool enabled)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlColliderEnabled(GetControl(windowName, controlName), enabled);
	}
	
	/// <summary>
	/// 设置控件碰撞属性开关
	/// </summary>
	public static void SetControlColliderEnabled(string windowName, string controlName, bool enabled)
	{
		SetControlColliderEnabled(GetControl(windowName, controlName), enabled);
	}
	
	/// <summary>
	/// 设置控件碰撞属性开关
	/// </summary>
	public static void SetControlColliderEnabled(Window window, string controlName, bool enabled)
	{
		SetControlColliderEnabled(GetControl(window, controlName), enabled);
	}
	
	/// <summary>
	/// 设置控件碰撞属性开关
	/// </summary>
	public static void SetControlColliderEnabled(GameObject control, bool enabled)
	{
		if(control == null)
			return;
		
		BoxCollider collider = control.GetComponent<BoxCollider>();
		if(collider != null)
			collider.enabled = enabled;
	}
	#endregion //Control Collider
	
	#region //Control Text
    /// <summary>
    /// 获取控件Txt
    /// </summary>
    public static string GetControlText(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlText(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件Txt
    /// </summary>
    public static string GetControlText(string windowName, string controlName)
    {
		return GetControlText(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件Txt
    /// </summary>
    public static string GetControlText(Window window, string controlName)
    {
		return GetControlText(GetControl(window, controlName));
	}
	
	/// <summary>
    /// 获取控件Txt
    /// </summary>
    public static string GetControlText(GameObject control)
    {
		if(control == null)
			return "";
		
        UILabel label = control.GetComponent<UILabel>();
		if(label != null)
			return label.text;
		
//		UIMix mix = control.GetComponent<UIMix>();
//		if(mix != null)
//			return mix.text;
		
		UIInput input = control.GetComponent<UIInput>();
		if(input != null)
			if(input.label != null)
				return label.text;
		
		UIButton button = control.GetComponent<UIButton>();
		if(button != null)
			if(button.label != null)
				return button.label.text;
		
		UIImageButton imageButton = control.GetComponent<UIImageButton>();
		if(imageButton != null)
			if(imageButton.label)
				return imageButton.label.text;
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
			if(checkbox.label != null)
				return checkbox.label.text;		
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
			if(list.textLabel != null)
				return list.textLabel.text;
		
		return "";
    }

    /// <summary>
    /// 设置控件Txt
    /// </summary>m>
    public static void SetControlText(string _controlName, string text)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlText(GetControl(windowName, controlName), text);
    }
	
	/// <summary>
    /// 设置控件Txt
    /// </summary>m>
    public static void SetControlText(string windowName, string controlName, string text)
    {
		SetControlText(GetControl(windowName, controlName), text);
	}
	
	/// <summary>
    /// 设置控件Txt
    /// </summary>m>
    public static void SetControlText(Window window, string controlName, string text)
    {
		SetControlText(GetControl(window, controlName), text);
	}
	
	/// <summary>
    /// 设置控件Txt
    /// </summary>m>
    public static void SetControlText(GameObject control, string text)
    {
		if( control == null )
			return;
		
		UILabel label = control.GetComponent<UILabel>();
		if(label != null)
		{
			label.text = text;
			return;
		}
		
//		UIMix mix = control.GetComponent<UIMix>();
//		if(mix != null)
//		{
//			mix.text = text;
//			return;
//		}
		
		UIInput input = control.GetComponent<UIInput>();
		if(input != null)
		{
			if(input.label != null)
			{
				label.text = text;
				return;
			}
		}
		
		UIButton button = control.GetComponent<UIButton>();
		if(button != null)
		{
			if(button.label != null)
			{
				button.label.text = text;				
				return;
			}
		}
		
		UIImageButton imageButton = control.GetComponent<UIImageButton>();
		if(imageButton != null)
		{
			if(imageButton.label)
			{
				imageButton.label.text = text;
				return;
			}
		}
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
		{
			if(checkbox.label != null)
			{
				checkbox.label.text = text;
				return;		
			}
		}
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
		{
			if(list.textLabel != null)
			{
				list.textLabel.text = text;
				return;
			}
		}
	}
    #endregion  //Control Text
	
	#region //Control LineWidth
	/// <summary>
    /// 获取控件字体行宽
    /// </summary>
    public static int GetControlLineWidth(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

		return GetControlLineWidth(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件字体行宽
    /// </summary>
    public static int GetControlLineWidth(string windowName, string controlName)
    {
		return GetControlLineWidth(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件字体行宽
    /// </summary>
    public static int GetControlLineWidth(Window window, string controlName)
    {
		return GetControlLineWidth(GetControl(window, controlName));
	}
	
	/// <summary>
    /// 获取控件字体行宽
    /// </summary>
    public static int GetControlLineWidth(GameObject control)
    {
		if(control == null)
			return 0;
		
		UILabel label = control.GetComponent<UILabel>();
        if (label != null)
            return label.lineWidth;
		
//		UIMix mix = control.GetComponent<UIMix>();
//		if(mix != null)
//			return mix.lineWidth;
		
		return 0;
	}
	
	/// <summary>
    /// 设置控件字体行宽
    /// </summary>
    public static void SetControlLineWidth(string _controlName, int lineWidth)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

		SetControlLineWidth(GetControl(windowName, controlName), lineWidth);
	}
	
	/// <summary>
    /// 设置控件字体行宽
    /// </summary>
    public static void SetControlLineWidth(string windowName, string controlName, int lineWidth)
    {
		SetControlLineWidth(GetControl(windowName, controlName), lineWidth);
	}
	
	/// <summary>
    /// 设置控件字体行宽
    /// </summary>
    public static void SetControlLineWidth(Window window, string controlName, int lineWidth)
    {
		SetControlLineWidth(GetControl(window, controlName), lineWidth);
	}
	
	/// <summary>
    /// 设置控件字体行宽
    /// </summary>
    public static void SetControlLineWidth(GameObject control, int lineWidth)
    {
        if (control == null)
			return;
		
        UILabel label = control.GetComponent<UILabel>();
        if (label != null)
		{
            label.lineWidth = lineWidth;
			return;
		}
		
//		UIMix mix = control.GetComponent<UIMix>();
//		if(mix != null)
//		{
//			mix.lineWidth = lineWidth;
//			return;
//		}
    }
	#endregion //Control LineWidth
	
	#region //Control SliderValue
	/// <summary>
    /// 获取标准控件滑动进度值
    /// </summary>
    public static float GetControlSliderValue(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlSliderValue(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取标准控件滑动进度值
    /// </summary>
    public static float GetControlSliderValue(string windowName, string controlName)
    {
		return GetControlSliderValue(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取标准控件滑动进度值
    /// </summary>
    public static float GetControlSliderValue(Window window, string controlName)
    {
		return GetControlSliderValue(GetControl(window, controlName));
    }
	
	/// <summary>
    /// 获取标准控件滑动进度值
    /// </summary>
    public static float GetControlSliderValue(GameObject control)
    {
		if(control == null)
			return 0;

        UISlider slider = control.GetComponent<UISlider>();
        if (slider != null)
            return slider.sliderValue;

        return 0;
    }

    /// <summary>
    /// 设置标准控件滑动进度值
    /// </summary>
    public static void SetControlSliderValue(string _controlName, float sliderValue)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

       	SetControlSliderValue(GetControl(windowName, controlName), sliderValue);
    }
	
	/// <summary>
    /// 设置标准控件滑动进度值
    /// </summary>
    public static void SetControlSliderValue(string windowName, string controlName, float sliderValue)
    {
		SetControlSliderValue(GetControl(windowName, controlName), sliderValue);
    }
	
	/// <summary>
    /// 设置标准控件滑动进度值
    /// </summary>
    public static void SetControlSliderValue(Window window, string controlName, float sliderValue)
    {
		SetControlSliderValue(GetControl(window, controlName), sliderValue);
    }
	
	/// <summary>
    /// 设置标准控件滑动进度值
    /// </summary>
    public static void SetControlSliderValue(GameObject control, float sliderValue)
    {
		if(control == null)
			return;
		
        UISlider slider = control.GetComponent<UISlider>();
        if (slider != null)
            slider.sliderValue = sliderValue;
    }
	#endregion //Control SliderValue
	
	#region //Control ScrollValue
	/// <summary>
    /// 获取标准控件滚动进度值
    /// </summary>
    public static float GetControlScrollValue(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlScrollValue(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取标准控件滚动进度值
    /// </summary>
    public static float GetControlScrollValue(string windowName, string controlName)
    {
		return GetControlScrollValue(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取标准控件滚动进度值
    /// </summary>
    public static float GetControlScrollValue(Window window, string controlName)
    {
		return GetControlScrollValue(GetControl(window, controlName));
	}
	
	/// <summary>
    /// 获取标准控件滚动进度值
    /// </summary>
    public static float GetControlScrollValue(GameObject control)
    {
		if(control == null)
			return 0;
		
		return GetControlScrollValue(control.GetComponent<UIScrollBar>());
	}
	
	/// <summary>
    /// 获取标准控件滚动进度值
    /// </summary>
    public static float GetControlScrollValue(UIScrollBar scroll)
    {
		if(scroll == null)
			return 0;
		
		return scroll.scrollValue;
	}
	
	/// <summary>
    /// 设置标准控件滚动进度值
    /// </summary>
    public static void SetControlScrollValue(string _controlName, float scrollValue)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlScrollValue(GetControl(windowName, controlName), scrollValue);
	}
	
	/// <summary>
    /// 设置标准控件滚动进度值
    /// </summary>
    public static void SetControlScrollValue(string windowName, string controlName, float scrollValue)
    {
		SetControlScrollValue(GetControl(windowName, controlName), scrollValue);
	}	
	
	/// <summary>
    /// 设置标准控件滚动进度值
    /// </summary>
    public static void SetControlScrollValue(Window window, string controlName, float scrollValue)
    {
		SetControlScrollValue(GetControl(window, controlName), scrollValue);
	}
	
	/// <summary>
    /// 设置标准控件滚动进度值
    /// </summary>
    public static void SetControlScrollValue(GameObject control, float scrollValue)
    {
		if(control == null)
			return;
		
		SetControlScrollValue(control.GetComponent<UIScrollBar>(), scrollValue);
	}
	
	/// <summary>
    /// 设置标准控件滚动进度值
    /// </summary>
    public static void SetControlScrollValue(UIScrollBar scroll, float scrollValue)
    {
		if(scroll == null)
			return;
		
		scroll.scrollValue = scrollValue;
	}
	#endregion //Control ScrollValue

    #endregion //Control Base

	
	
    #region //Standard Control

    #region //Control BackGround	
	/// <summary>
	/// 获取控件的背景
	/// </summary>
	public static GameObject GetControlBackGround(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlBackGround(GetControl(windowName, controlName));	
	}
	
	/// <summary>
	/// 获取控件的背景
	/// </summary>
	public static GameObject GetControlBackGround(string windowName, string controlName)
    {
		return GetControlBackGround(GetControl(windowName, controlName));	
	}
	
	/// <summary>
	/// 获取控件的背景
	/// </summary>
	public static GameObject GetControlBackGround(Window window, string controlName)
    {
		return GetControlBackGround(GetControl(window, controlName));	
	}
	
	/// <summary>
	/// 获取控件的背景
	/// </summary>
	public static GameObject GetControlBackGround(GameObject control)
    {
		if(control == null)
			return null;
		
		UIButton button = control.GetComponent<UIButton>();
		if(button != null)
			if(button.background != null)
				return button.background.gameObject;
		
		UIImageButton imageButton = control.GetComponent<UIImageButton>();
		if(imageButton != null)
			if(imageButton.target)
				return imageButton.target.gameObject;
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
			if(checkbox.backGround != null)
				return checkbox.backGround.gameObject;
		
		UISlider slider = control.GetComponent<UISlider>();
		if(slider != null)
			if(slider.backround != null)
				return slider.backround.gameObject;
		
		UIInput input = control.GetComponent<UIInput>();
		if(input != null)
			if(input.background != null)
				return input.background.gameObject;
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
			if(list.menuground != null)
				return list.menuground.gameObject;
		
		UIScrollBar scroll = control.GetComponent<UIScrollBar>();
		if(scroll != null)
			if(scroll.background != null)
				return scroll.background.gameObject;
		
		return null;
	}	
	
	/// <summary>
	/// 获取控件的背景图片名字
	/// </summary>
	public static string GetControlBackGroundName(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlBackGroundName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件的背景图片名字
	/// </summary>
	public static string GetControlBackGroundName(string windowName, string controlName)
    {
		return GetControlBackGroundName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件的背景图片名字
	/// </summary>
	public static string GetControlBackGroundName(Window window, string controlName)
    {
		return GetControlBackGroundName(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件的背景图片名字
	/// </summary>
	public static string GetControlBackGroundName(GameObject control)
    {
		GameObject controlBackground = GetControlBackGround(control);
		if(controlBackground == null)
			return null;
		
		return controlBackground.name;
	}
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(string _controlName, GameObject background)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlBackGround(GetControl(windowName, controlName), background);
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(string windowName, string controlName, GameObject background)
    {
		SetControlBackGround(GetControl(windowName, controlName), background);
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(Window window, string controlName, GameObject background)
    {
		SetControlBackGround(GetControl(window, controlName), background);
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(GameObject control, GameObject background)
    {
		if(control == null || background == null)
			return;
		
		SetControlBackGround(control, background.GetComponent<UISprite>());
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(string _controlName, UISprite bgSprite)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlBackGround(GetControl(windowName, controlName), bgSprite);
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(string windowName, string controlName, UISprite bgSprite)
    {
		SetControlBackGround(GetControl(windowName, controlName), bgSprite);
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(Window window, string controlName, UISprite bgSprite)
    {
		SetControlBackGround(GetControl(window, controlName), bgSprite);
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(GameObject control, UISprite bgSprite)
    {
		if(control == null || bgSprite == null)
			return;
        
		GameObject bgControl= GetControlBackGround(control);
		if(bgControl == null)
			return;		
		
		UIButton button = bgControl.GetComponent<UIButton>();
		if(button != null)
		{
			button.background = bgSprite;
			return;
		}
		
		UIImageButton imageButton = bgControl.GetComponent<UIImageButton>();
		if(imageButton != null)
		{
			imageButton.target = bgSprite;
			return;
		}
		
		UICheckbox checkbox = bgControl.GetComponent<UICheckbox>();
		if(checkbox != null)
		{
			checkbox.backGround = bgSprite;
			return;
		}
		
		UISlider slider = bgControl.GetComponent<UISlider>();
		if(slider != null)
		{
			slider.backround = bgSprite.transform;
			return;
		}
		
		UIInput input = bgControl.GetComponent<UIInput>();
		if(input != null)
		{
			input.background = bgSprite;
			return;
		}
		
		UIPopupList list = bgControl.GetComponent<UIPopupList>();
		if(list != null)
		{
			list.menuground = bgSprite;
			return;
		}
		
		UIScrollBar scroll = bgControl.GetComponent<UIScrollBar>();
		if(scroll != null)
		{
			scroll.background = bgSprite;
			return;
		}
    }
    #endregion //Control BackGround

    #region //Control Foreground
	/// <summary>
	/// 获取控件前景控件
	/// </summary>
	public static GameObject GetControlForeground(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlForeground(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件前景控件
	/// </summary>
	public static GameObject GetControlForeground(string windowName, string controlName)
    {
		return GetControlForeground(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件前景控件
	/// </summary>
	public static GameObject GetControlForeground(Window window, string controlName)
    {
		return GetControlForeground(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件前景控件
	/// </summary>
	public static GameObject GetControlForeground(GameObject control)
    {
		if(control == null)
			return null;
		
		UISlider slider = control.GetComponent<UISlider>();
		if(slider != null)
			if(slider.foreground != null)
				return slider.foreground.gameObject;
		
		return null;
	}
	
	/// <summary>
	/// 获取控件前景控件名字
	/// </summary>
	public static string GetControlForegroundName(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlForegroundName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件前景控件名字
	/// </summary>
	public static string GetControlForegroundName(string windowName, string controlName)
    {
		return GetControlForegroundName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件前景控件名字
	/// </summary>
	public static string GetControlForegroundName(Window window, string controlName)
    {
		return GetControlForegroundName(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件前景控件名字
	/// </summary>
	public static string GetControlForegroundName(GameObject control)
    {
		GameObject fgControl = GetControlForeground(control);
		if(fgControl == null)
			return null;
		
		return fgControl.name;
	}
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(string _controlName, GameObject foreground)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlForeground(GetControl(windowName, controlName), foreground);
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(string windowName, string controlName, GameObject foreground)
    {
		SetControlForeground(GetControl(windowName, controlName), foreground);
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(Window window, string controlName, GameObject foreground)
    {
		SetControlForeground(GetControl(window, controlName), foreground);
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(GameObject control, GameObject foreground)
    {
		if(control == null || foreground == null)
			return;
        
		SetControlForeground(control, foreground.GetComponent<UISprite>());
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(string _controlName, UISprite fgSprite)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlForeground(GetControl(windowName, controlName), fgSprite);
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(string windowName, string controlName, UISprite fgSprite)
    {
		SetControlForeground(GetControl(windowName, controlName), fgSprite);
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(Window window, string controlName, UISprite fgSprite)
    {
		SetControlForeground(GetControl(window, controlName), fgSprite);
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(GameObject control, UISprite fgSprite)
    {
		if(control == null || fgSprite == null)
			return;
        
		GameObject fgControl= GetControlForeground(control);
		if(fgControl == null)
			return;		

		UISlider slider = fgControl.GetComponent<UISlider>();
		if(slider != null)
		{
			slider.foreground = fgSprite.transform;
			return;
		}
    }
    #endregion //Control Foreground

    #region //Control Checkmark
	/// <summary>
	/// 获取标准控件的选中Mark控件
	/// </summary>
	public static GameObject GetControlCheckmark(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlCheckmark(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件
	/// </summary>
	public static GameObject GetControlCheckmark(string windowName, string controlName)
    {
		return GetControlCheckmark(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件
	/// </summary>
	public static GameObject GetControlCheckmark(Window window, string controlName)
    {
		return GetControlCheckmark(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件
	/// </summary>
	public static GameObject GetControlCheckmark(GameObject control)
    {
		if(control == null)
			return null;
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
			if(checkbox.checkSprite != null)
				return checkbox.checkSprite.gameObject;
		
		return null;
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件名字
	/// </summary>
	public static string GetControlCheckmarkName(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlCheckmarkName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件名字
	/// </summary>
	public static string GetControlCheckmarkName(string windowName, string controlName)
    {
		return GetControlCheckmarkName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件名字
	/// </summary>
	public static string GetControlCheckmarkName(Window window, string controlName)
    {		
		return GetControlCheckmarkName(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件名字
	/// </summary>
	public static string GetControlCheckmarkName(GameObject control)
    {
		GameObject cmControl = GetControlCheckmark(control);
		if(cmControl == null)
			return null;
		
		return cmControl.name;
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(string _controlName, GameObject checkmark)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlCheckmark(GetControl(windowName, controlName), checkmark);
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(string windowName, string controlName, GameObject checkmark)
    {
		SetControlCheckmark(GetControl(windowName, controlName), checkmark);
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(Window window, string controlName, GameObject checkmark)
    {
		SetControlCheckmark(GetControl(window, controlName), checkmark);
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(GameObject control, GameObject checkmark)
    {
		if(control == null || checkmark == null)
			return;
		
		SetControlCheckmark(control, checkmark.GetComponent<UISprite>());
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(string _controlName, UISprite cmSprite)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlCheckmark(GetControl(windowName, controlName), cmSprite);
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(string windowName, string controlName, UISprite cmSprite)
    {
		SetControlCheckmark(GetControl(windowName, controlName), cmSprite);
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(Window window, string controlName, UISprite cmSprite)
    {
		SetControlCheckmark(GetControl(window, controlName), cmSprite);
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(GameObject control, UISprite cmSprite)
    {
		if(control == null || cmSprite == null)
			return;
		
		GameObject cmControl = GetControlCheckmark(control);
		if(control == null)
			return;
		
		UICheckbox checkbox = cmControl.GetComponent<UICheckbox>();
		if(checkbox != null)
		{
			checkbox.checkSprite = cmSprite;
			return;
		}
	}
    #endregion //Control Checkmark

    #region //Control Thumb
	/// <summary>
	/// 获取控件游标
	/// </summary>
	public static GameObject GetControlThumb(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlThumb(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件游标
	/// </summary>
	public static GameObject GetControlThumb(string windowName, string controlName)
    {
		return GetControlThumb(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件游标
	/// </summary>
	public static GameObject GetControlThumb(Window window, string controlName)
    {
		return GetControlThumb(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件游标
	/// </summary>
	public static GameObject GetControlThumb(GameObject control)
    {
		if(control == null)
			return null;
		
		UISlider slider = control.GetComponent<UISlider>();
		if(slider != null)
			if(slider.thumb != null)
				return slider.thumb.gameObject;
		
		return null;
	}
	
	/// <summary>
	/// 获取控件游标名字
	/// </summary>
	public static string GetControlThumbName(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlThumbName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件游标名字
	/// </summary>
	public static string GetControlThumbName(string windowName, string controlName)
    {
		return GetControlThumbName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件游标名字
	/// </summary>
	public static string GetControlThumbName(Window window, string controlName)
    {
		return GetControlThumbName(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件游标名字
	/// </summary>
	public static string GetControlThumbName(GameObject control)
    {
		GameObject tbControl = GetControlThumb(control);
		if(tbControl == null)
			return null;
		
		return tbControl.name;
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(string _controlName, GameObject thumb)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlThumb(GetControl(windowName, controlName), thumb);
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(string windowName, string controlName, GameObject thumb)
    {
		SetControlThumb(GetControl(windowName, controlName), thumb);
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(Window window, string controlName, GameObject thumb)
    {
		SetControlThumb(GetControl(window, controlName), thumb);
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(GameObject control, GameObject thumb)
    {
		if(control == null || thumb == null)
			return;
		
		SetControlThumb(GetControlThumb(control), thumb);
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(string _controlName, UISprite tbSprite)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlThumb(GetControl(windowName, controlName), tbSprite);
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(string windowName, string controlName, UISprite tbSprite)
    {
		SetControlThumb(GetControl(windowName, controlName), tbSprite);
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(Window window, string controlName, UISprite tbSprite)
    {
		SetControlThumb(GetControl(window, controlName), tbSprite);
	}
	
    /// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(GameObject control, UISprite tbSprite)
    {
		if(control == null || tbSprite == null)
			return;
		
		GameObject tbControl = GetControlThumb(control);
		if(tbControl == null)		
			return;
		
		UISlider slider = tbControl.GetComponent<UISlider>();
		if(slider != null)
		{
			slider.thumb = tbSprite.transform;
			return;
		}
	}
    #endregion //Control Thumb

    #region //Control Label
	/// <summary>
	/// 获取控件的Lable控件
	/// </summary>
	public static GameObject GetControlLabel(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlLabel(GetControl(windowName, controlName));
    }
	
	/// <summary>
	/// 获取控件的Lable控件
	/// </summary>
	public static GameObject GetControlLabel(string windowName, string controlName)
    {
       return GetControlLabel(GetControl(windowName, controlName));
    }
	
	/// <summary>
	/// 获取控件的Lable控件
	/// </summary>
	public static GameObject GetControlLabel(Window window, string controlName)
    {
       return GetControlLabel(GetControl(window, controlName));
    }
	
	/// <summary>
	/// 获取控件的Lable控件
	/// </summary>
	public static GameObject GetControlLabel(GameObject control)
    {
        if(control == null)
			return null;
		
		UIButton button = control.GetComponent<UIButton>();
		if(button != null)
			if(button.label != null)
				return button.label.gameObject;
		
		UIImageButton imageButton = control.GetComponent<UIImageButton>();
		if(imageButton != null)
			if(imageButton.label)
				return imageButton.label.gameObject;
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
			if(checkbox.label != null)
				return checkbox.label.gameObject;
		
		UIInput input = control.GetComponent<UIInput>();
		if(input != null)
			if(input.label != null)
				return input.label.gameObject;
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
			if(list.textLabel != null)
				return list.textLabel.gameObject;
	
		return null;
    }
	
	/// <summary>
	/// 获取控件的Lable控件名字
	/// </summary>
	public static string GetControlLabelName(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlLabelName(GetControl(windowName, controlName));
    }
	
	/// <summary>
	/// 获取控件的Lable控件名字
	/// </summary>
	public static string GetControlLabelName(string windowName, string controlName)
    {
		return GetControlLabelName(GetControl(windowName, controlName));
    }
	
	/// <summary>
	/// 获取控件的Lable控件名字
	/// </summary>
	public static string GetControlLabelName(Window window, string controlName)
    {
		return GetControlLabelName(GetControl(window, controlName));
    }
	
	/// <summary>
	/// 获取控件的Lable控件名字
	/// </summary>
	public static string GetControlLabelName(GameObject control)
    {
        GameObject lbControl = GetControlLabel(control);
		if(lbControl == null)
			return null;
		
		return lbControl.name;
    }
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(string _controlName, GameObject lable)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlLabel(GetControl(windowName, controlName), lable);
	}
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(string windowName, string controlName, GameObject lable)
    {
		SetControlLabel(GetControl(windowName, controlName), lable);
	}
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(Window window, string controlName, GameObject lable)
    {
		SetControlLabel(GetControl(window, controlName), lable);
	}	
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(GameObject control, GameObject lable)
    {
		if(control == null || lable == null)
			return;
		
		SetControlLabel(control, lable.GetComponent<UILabel>());
	}
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(string _controlName, UILabel lable)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlLabel(GetControl(windowName, controlName), lable);
	}
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(string windowName, string controlName, UILabel lable)
    {
		SetControlLabel(GetControl(windowName, controlName), lable);
	}
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(Window window, string controlName, UILabel lable)
    {
		SetControlLabel(GetControl(window, controlName), lable);
	}
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(GameObject control, UILabel lable)
    {
		if(control == null || lable == null)
			return;
		
		GameObject lbControl = GetControlLabel(control);
		if(lbControl == null)
			return;
		
		UIButton button = control.GetComponent<UIButton>();
		if(button != null)
		{
			button.label = lable;
			return;
		}
		
		UIImageButton imageButton = control.GetComponent<UIImageButton>();
		if(imageButton != null)
		{
			imageButton.label = lable;
			return;
		}
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
		{
			checkbox.label = lable;
			return;
		}
		
		UIInput input = control.GetComponent<UIInput>();
		if(input != null)
		{
			input.label = lable;
			return;
		}
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
		{
			list.textLabel = lable;
			return;
		}
    }
    #endregion  //Control Label

    #region //Control Slider
    /// <summary>
    /// 设置标准控件滑动进度值
    /// </summary>
    public static void SetControlSliderFullWidth(string _controlName, float width)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
            UISlider slider = controlObj.GetComponent<UISlider>();
            if (slider != null)
                slider.fullSize = new Vector2(width, slider.fullSize.y);
        }
    }
    #endregion //Control Slider

    #region //Control Group
	/// <summary>
	/// 获取Group控件元素个数
	/// </summary>
	public static int GetGroupControlItemCount(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetGroupControlItemCount(GetControl(windowName, controlName));
	}	
	
	/// <summary>
	/// 获取Group控件元素个数
	/// </summary>
	public static int GetGroupControlItemCount(string windowName, string controlName)
	{
		return GetGroupControlItemCount(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取Group控件元素个数
	/// </summary>
	public static int GetGroupControlItemCount(Window window, string controlName)
	{
		return GetGroupControlItemCount(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取Group控件元素个数
	/// </summary>
	public static int GetGroupControlItemCount(GameObject control)
	{
		if(control == null)
			return 0;
		
		UITable table = control.GetComponent<UITable>();
        if (table != null)
            return table.children.Count;
		
		UICheckboxGroup cbGroup = control.GetComponent<UICheckboxGroup>();
		if(cbGroup != null)
			return cbGroup.childeren.Count;
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
			return list.items.Count;
		
		return 0;
	}
	
    /// <summary>
    /// 向Table控件添加一个元素
    /// </summary>
    public static GameObject AddItemToTable(string newItemName, string tableControl)
    {
        return AddItemToTable(newItemName, tableControl, -1);
    }
	
	/// <summary>
    /// 向Table控件添加一个元素
    /// </summary>
    public static GameObject AddItemToTable(string newItemName, GameObject tableControl)
    {
      	return AddItemToTable(newItemName, tableControl, -1);
    }

    /// <summary>
    /// 向Table控件添加一个元素,并指定序号
    /// </summary>
    public static GameObject AddItemToTable(string newItemName, string tableControl, int index)
    {
        string windowName = tableControl.Split('_')[0];
        string controlName = tableControl.Substring(windowName.Length + 1);

       	return AddItemToTable(newItemName, GetControl(windowName, controlName), index);
    }
	
	/// <summary>
    /// 向Table控件添加一个元素,并指定序号
    /// </summary>
	public static GameObject AddItemToTable(string newItemName, GameObject tableControl, int index)
    {
		if (tableControl == null)
        	return null;
	
        UITable table = tableControl.GetComponent<UITable>();
        if (table != null)
			return AddItemToTable(newItemName, table, index);
		
		return null;
	}
	
	/// <summary>
    /// 向Grid控件添加一个元素,并指定序号
    /// </summary>
	public static GameObject AddItemToGrid(string newItemName, GameObject gridControl, int index)
    {
		if (gridControl == null)
        	return null;
		
		UIGrid grid = gridControl.GetComponent<UIGrid>();
		if(grid != null)
			return AddItemToGrid(newItemName, grid, index);
		
		return null;
	}
	
	/// <summary>
    /// 向Table控件添加一个元素,并指定序号
    /// </summary>
	public static GameObject AddItemToTable(string newItemName, UITable table)
	{
		return AddItemToTable(newItemName, table, -1);
	}
	
	/// <summary>
    /// 向Grid控件添加一个元素,并指定序号
    /// </summary>
	public static GameObject AddItemToGrid(string newItemName, UIGrid grid)
	{
		return AddItemToGrid(newItemName, grid, -1);
	}
	
	/// <summary>
    /// 向Table控件添加一个元素,并指定序号
    /// </summary>
	public static GameObject AddItemToTable(string newItemName, UITable table, int index)
	{
        if (table == null)
            return null;
		
		if(table.itemTemplate == null)
			return null;
		
//        Transform newItem = table.transform.FindChild(newItemName);
//        if (newItem != null)
//            return null;
		
		Transform itemTrans = table.itemTemplate.transform;
        GameObject newItemObj = Instantiate(table.itemTemplate) as GameObject;
		newItemObj.SetActiveRecursively(true);
		newItemObj.name = (string.IsNullOrEmpty(newItemName) ? table.itemTemplate.name : newItemName);
		
		Transform newItem = newItemObj.transform;       
        newItem.parent = table.transform;
        newItem.localPosition = itemTrans.localPosition;
        newItem.localRotation = itemTrans.localRotation;
        newItem.localScale = itemTrans.localScale;
		
		if(index == -1)
			index = table.children.Count;

		if(index >= 0 && index <= table.children.Count)
		{
			table.children.Insert(index, newItem);
			table.Reposition(false);
			
			return newItem.gameObject;
		}
		else
		{
			DestroyImmediate(newItemObj);
		}
		
		return null;
	}
	
	/// <summary>
    /// 向Grid控件添加一个元素,并指定序号
    /// </summary>
	public static GameObject AddItemToGrid(string newItemName, UIGrid grid, int index)
	{
        if (grid == null)
            return null;
		
		if(grid.itemTemplate == null)
			return null;
		
        Transform newItem = grid.transform.FindChild(newItemName);
        if (newItem != null)
            return null;
		
		Transform itemTrans = grid.itemTemplate.transform;
        GameObject newItemObj = Instantiate(grid.itemTemplate) as GameObject;
		newItemObj.SetActiveRecursively(true);
		newItemObj.name = newItemName;
		
		newItem = newItemObj.transform;       
        newItem.parent = grid.transform;
        newItem.localPosition = itemTrans.localPosition;
        newItem.localRotation = itemTrans.localRotation;
        newItem.localScale = itemTrans.localScale;
		
		if(index == -1)
			index = grid.children.Count;

		if(index >= 0 && index <= grid.children.Count)
		{
			grid.children.Insert(index, newItem);
			grid.Reposition();
			
			return newItem.gameObject;
		}
		else
		{
			DestroyImmediate(newItemObj);
		}
		
		return null;
	}
	
	/// <summary>
	/// Removes the item at form table.
	/// </summary>
	/// </param>
	public static void RemoveItemAtFromTable(string tableControl, int index)
	{
		string windowName = tableControl.Split('_')[0];
        string controlName = tableControl.Substring(windowName.Length + 1);
		
		RemoveItemAtFromTable(GetControl(windowName, controlName), index);		
	}
	
	//删除Table表中指定的元素
	public static void RemoveItemAtFromTable(GameObject control, int index)
	{
		UITable table = control.GetComponent<UITable>();
        if (table == null)
            return;
		
		if(index >= 0 && index < table.children.Count)
		{
			DestroyImmediate(table.children[index]);
			table.children.RemoveAt(index);
			table.Reposition(false);
		}
	}
	
	public static void RemoveItemAtFromTable( GameObject control, string name )
	{
		UITable table = control.GetComponent<UITable>();
        if (table == null)
            return;
		if( name == "" )
			return;
		table.DestroyChild( name );
	}
	
	/// <summary>
	/// Gets the index of the table group hovered.
	/// </summary>
	/// <returns>
	public static int GetTableGroupHoveredIndex(string _controlName)
	{
		GameObject hoveredObject = UICamera.currentTouch.current;
		if(hoveredObject == null)
			return -1;
		
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
			UITable table = controlObj.GetComponent<UITable>();
			if(table != null)
			{
				for(int i = 0; i < table.children.Count; i++)
				{
					if(NGUITools.IsChild(table.children[i], controlObj.transform))
						return i;
				}
			}
			
			for(int i = 0; i < controlObj.transform.childCount; i++)
			{
				if(hoveredObject.transform.IsChildOf(controlObj.transform.GetChild(i)))
					return i;
			}
		}
		
		return -1;
	}
	
	/// <summary>
	/// Gets the index of the table group selected.
	/// </summary>
	public static int GetTableGroupSelectedIndex(string _controlName)
	{
		GameObject selectedObject = UICamera.selectedObject;
		if(selectedObject == null)
			return -1;
		
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
			UITable table = controlObj.GetComponent<UITable>();
			if(table != null)
			{
				for(int i = 0; i < table.children.Count; i++)
				{
					if(NGUITools.IsChild(table.children[i], controlObj.transform))
						return i;
				}
			}
			
			for(int i = 0; i < controlObj.transform.childCount; i++)
			{
				if(selectedObject.transform.IsChildOf(controlObj.transform.GetChild(i)))
					return i;
			}
		}
		
		return -1;
	}
	
	/// <summary>
	/// Sets the index of the tale group selected.
	/// </summary>
	public static void SetTaleGroupSelectedIndex(string _controlName, int index)
	{
		if(index < 0)
			return;
		
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
			UITable tabel = controlObj.GetComponent<UITable>();
			if(tabel != null)
			{
				if(index < tabel.children.Count)
				{					
					Transform child = tabel.children[index];
					if(child != null)
					{
						UICamera.selectedObject = child.gameObject;					
						
						UIImageButton button = child.GetComponent<UIImageButton>();
						if(button != null)
						{
							if(button.target != null)
								button.target.spriteName = button.pressedSprite;
						}
						else
						{
							UICheckbox checkbox = child.GetComponent<UICheckbox>();
							if(checkbox != null)
								checkbox.isChecked = true;
						}
					}
				}
			}
		}
	}
    #endregion  //Control Group
	
	#region //Control RadioGroup
	/// <summary>
	/// Gets the index of the radio group state by.
	/// </summary>
	public static bool GetRadioGroupCheckedStateByIndex(string _controlName, int index)
	{
		if(index < 0)
			return false;
		
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
			UICheckboxGroup checkboxGroup = controlObj.GetComponent<UICheckboxGroup>();
			if(checkboxGroup != null)
			{
				if(index >= checkboxGroup.childeren.Count)
					return false;
				
				UICheckbox checkbox = checkboxGroup.childeren[index];
				if(checkbox != null)
					return checkbox.isChecked;
			}
		}
		
		return false;
	}
	
	/// <summary>
	/// Sets the index of the radio group checked.
	/// </summary>
	public static void SetRadioGroupCheckedIndex(string _controlName, int index)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
			UICheckboxGroup checkboxGroup = controlObj.GetComponent<UICheckboxGroup>();
			if(checkboxGroup != null)
				checkboxGroup.SetCheckedIndex(index);
		}
	}
	
	/// <summary>
	/// Gets the index of the radio group checked.
	/// </summary>
	public static int GetRadioGroupCheckedIndex(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
			UICheckboxGroup checkboxGroup = controlObj.GetComponent<UICheckboxGroup>();
			if(checkboxGroup != null)
				return checkboxGroup.checkedIndex;
		}
		
		return -1;
	}
	#endregion //Control RadioGroup

    #endregion //Standard Control



//    #region //Create UI
//
//    #region //Panel & Window
//    public static UIPanel CreatPanel(GameObject parent, string name)
//    {
//        UIPanel panel = NGUITools.AddChild<UIPanel>(parent);
//        panel.name = name;
//
//        return panel;
//    }
//
//    public static Window CreatWindow(GameObject parent, string name)
//    {
//        Window window = GetWindow(name);
//        if(window != null)
//            return window;
//
//        UIPanel panel = CreatPanel(parent, name);
//		window = panel.gameObject.AddComponent<Window>();
//        windows.Add(name, window);
//
//        return window;
//    }
//    #endregion //Panel & Window
//
//    #region //Label
//    public static UILabel CreateLabel(GameObject parent, string name)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        UILabel label = NGUITools.AddWidget<UILabel>(parent);
//        label.name = name;
//        label.depth = depth;
//
//        label.font = defaultFont;
//        label.MakePixelPerfect();
//
//        return label;
//    }
//    #endregion //Label
//
//    #region //Sprite
//    public static T CreateSprite<T>(GameObject parent, string name) where T : UISprite
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        T sprite = NGUITools.AddChild<T>(parent);
//        sprite.name = name;
//        sprite.depth = depth;
//
//        sprite.atlas = defaultAtlas;
//        SetDefualtScale(sprite);
//
//        return sprite;
//    }
//
//    public static UISprite CreateSprite(GameObject parent, string name)
//    {
//        return CreateSprite<UISprite>(parent, name);
//    }
//
//    public static UISlicedSprite CreateSlicedSprite(GameObject parent, string name)
//    {
//        return CreateSprite<UISlicedSprite>(parent, name);
//    }
//
//    public static UITiledSprite CreateTiledSprite(GameObject parent, string name)
//    {
//        return CreateSprite<UITiledSprite>(parent, name);
//    }
//
//    public static UIFilledSprite CreateFilledSprite(GameObject parent, string name)
//    {
//        return CreateSprite<UIFilledSprite>(parent, name);
//    }
//    #endregion //Sprite
//
//    #region //Button
//    public static UIButton CreateButton(GameObject parent, string name)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        GameObject go = NGUITools.AddChild(parent);
//        go.name = name;
//
//        UISlicedSprite bg = NGUITools.AddWidget<UISlicedSprite>(go);
//        bg.name = "Background";
//        bg.depth = depth;
//        bg.atlas = defaultAtlas;
//        bg.transform.localScale = new Vector3(150f, 40f, 1f);
//        bg.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(bg);
//
//        UILabel lbl = NGUITools.AddWidget<UILabel>(go);
//        lbl.font = defaultFont;
//        lbl.text = go.name;
//        lbl.MakePixelPerfect();
//
//        // Add a collider
//        NGUITools.AddWidgetCollider(go);
//
//        // Add the scripts
//        go.AddComponent<UIButton>().tweenTarget = bg.gameObject;
//        go.AddComponent<UIButtonScale>();
//        go.AddComponent<UIButtonOffset>();
//        go.AddComponent<UIButtonSound>();
//
//        return go.GetComponent<UIButton>();
//    }
//
//    public static UIImageButton CreateImageButton(GameObject parent, string name)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        GameObject go = NGUITools.AddChild(parent);
//        go.name = name;
//
//        UISlicedSprite sprite = NGUITools.AddWidget<UISlicedSprite>(go);
//
//        sprite.name = "Background";
//        sprite.depth = depth;
//        sprite.atlas = defaultAtlas;
//        sprite.transform.localScale = new Vector3(150f, 40f, 1f);
//        sprite.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(sprite);
//
//        // Add a collider
//        NGUITools.AddWidgetCollider(go);
//
//        // Add the scripts
//        UIImageButton ib = go.AddComponent<UIImageButton>();
//        ib.target = sprite;
//        go.AddComponent<UIButtonSound>();
//
//        return ib;
//    }
//    #endregion //Button
//
//    #region //CheckBox
//    public static UICheckbox CreateCheckbox(GameObject parent, string name)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        GameObject go = NGUITools.AddChild(parent);
//        go.name = "Checkbox";
//
//        UISlicedSprite bg = NGUITools.AddWidget<UISlicedSprite>(go);
//        bg.name = "Background";
//        bg.depth = depth;
//        bg.atlas = defaultAtlas;
//        bg.transform.localScale = new Vector3(26f, 26f, 1f);
//        bg.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(bg);
//
//        UISprite fg = NGUITools.AddWidget<UISprite>(go);
//        fg.name = "Checkmark";
//        fg.atlas = defaultAtlas;
//        fg.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(fg);
//
//        UILabel lbl = NGUITools.AddWidget<UILabel>(go);
//        lbl.font = defaultFont;
//        lbl.text = go.name;
//        lbl.pivot = UIWidget.Pivot.Left;
//        lbl.transform.localPosition = new Vector3(16f, 0f, 0f);
//        lbl.MakePixelPerfect();
//
//        // Add a collider
//        NGUITools.AddWidgetCollider(go);
//
//        // Add the scripts
//        go.AddComponent<UICheckbox>().checkSprite = fg;
//        go.AddComponent<UIButton>().tweenTarget = bg.gameObject;
//        go.AddComponent<UIButtonScale>().tweenTarget = bg.transform;
//        go.AddComponent<UIButtonSound>();
//
//        return  go.AddComponent<UICheckbox>();
//    }
//    #endregion //CheckBox
//
//    #region //Slider
//    public static UISlider CreateSlider(GameObject parent, string name)
//    {
//        return CreateBaseSlider(parent, name, true);
//    }
//
//    public static UISlider CreateProgressBar(GameObject parent, string name)
//    {
//        return CreateBaseSlider(parent, name, false);
//    }
//
//    static UISlider CreateBaseSlider(GameObject parent, string name, bool slider)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        GameObject go = NGUITools.AddChild(parent);
//        go.name = name;
//
//        // Background sprite
//        UISprite back = NGUITools.AddWidget<UISlicedSprite>(go);
//
//        back.name = "Background";
//        back.depth = depth;
//        back.pivot = UIWidget.Pivot.Left;
//        back.atlas = defaultAtlas;
//        back.transform.localScale = new Vector3(200f, 30f, 1f);
//        back.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(back);
//
//        // Fireground sprite
//        UISprite front = NGUITools.AddWidget<UISlicedSprite>(go);
//
//        front.name = "Foreground";
//        front.pivot = UIWidget.Pivot.Left;
//        front.atlas = defaultAtlas;
//        front.transform.localScale = new Vector3(200f, 30f, 1f);
//        front.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(front);
//
//        // Add a collider
//        if (slider) NGUITools.AddWidgetCollider(go);
//
//        // Add the slider script
//        UISlider uiSlider = go.AddComponent<UISlider>();
//        uiSlider.foreground = front.transform;
//        uiSlider.fullSize = front.transform.localScale;
//
//        // Thumb sprite
//        if (slider)
//        {
//            UISprite thb = NGUITools.AddWidget<UISlicedSprite>(go);
//
//            thb.name = "Thumb";
//            thb.atlas = defaultAtlas;
//            thb.transform.localPosition = new Vector3(200f, 0f, 0f);
//            thb.transform.localScale = new Vector3(20f, 40f, 1f);
//            thb.MakePixelPerfect();
//            //sclae to the defualt
//            SetDefualtScale(thb);
//
//            NGUITools.AddWidgetCollider(thb.gameObject);
//            thb.gameObject.AddComponent<UIButtonColor>();
//            thb.gameObject.AddComponent<UIButtonScale>();
//
//            uiSlider.thumb = thb.transform;
//        }
//        uiSlider.sliderValue = 0.75f;
//
//        return go.GetComponent<UISlider>();
//    }
//    #endregion //Slider
//
//    #region //Input
//    public static UIInput CreateInput(GameObject parent, string name)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        GameObject go = NGUITools.AddChild(parent);
//        go.name = name;
//
//        float padding = 3f;
//
//        UISlicedSprite bg = NGUITools.AddWidget<UISlicedSprite>(go);
//        bg.name = "Background";
//        bg.depth = depth;
//        bg.atlas = defaultAtlas;
//        bg.pivot = UIWidget.Pivot.Left;
//        bg.transform.localScale = new Vector3(400f, defaultFont.size + padding * 2f, 1f);
//        bg.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(bg);
//
//        UILabel lbl = NGUITools.AddWidget<UILabel>(go);
//        lbl.font = defaultFont;
//        lbl.pivot = UIWidget.Pivot.Left;
//        lbl.transform.localPosition = new Vector3(padding, 0f, 0f);
//        lbl.multiLine = false;
//        lbl.supportEncoding = false;
//        lbl.lineWidth = Mathf.RoundToInt(400f - padding * 2f);
//        lbl.text = "You can type here";
//        lbl.MakePixelPerfect();
//
//        // Add a collider to the background
//        NGUITools.AddWidgetCollider(go);
//
//        // Add an input script to the background and have it point to the label
//        UIInput input = go.AddComponent<UIInput>();
//        input.label = lbl;
//
//        return input;
//    }
//    #endregion //Input
//
//    #region //PopList
//    public static UIPopupList CreatePopList(GameObject parent, string name)
//    {
//        return CreateBasePopList(parent, name, true);
//    }
//
//    public static UIPopupList CreatePopMenu(GameObject parent, string name)
//    {
//        return CreateBasePopList(parent, name, false);
//    }
//
//    static UIPopupList CreateBasePopList(GameObject parent, string name, bool isDropDown)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        GameObject go = NGUITools.AddChild(parent);
//        go.name = name;
//
//        UIAtlas.Sprite sphl = defaultAtlas.GetSprite("");
//        UIAtlas.Sprite spfg = defaultAtlas.GetSprite("");
//
//        Vector2 hlPadding = new Vector2(
//            Mathf.Max(4f, sphl.inner.xMin - sphl.outer.xMin),
//            Mathf.Max(4f, sphl.inner.yMin - sphl.outer.yMin));
//
//        Vector2 fgPadding = new Vector2(
//            Mathf.Max(4f, spfg.inner.xMin - spfg.outer.xMin),
//            Mathf.Max(4f, spfg.inner.yMin - spfg.outer.yMin));
//
//        // Background sprite
//        UISprite sprite = NGUITools.AddSprite(go, defaultAtlas, "");
//        sprite.depth = depth;
//        sprite.atlas = defaultAtlas;
//        sprite.transform.localScale = new Vector3(150f + fgPadding.x * 2f, defaultFont.size + fgPadding.y * 2f, 1f);
//        sprite.pivot = UIWidget.Pivot.Left;
//        sprite.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(sprite);
//
//        // Text label
//        UILabel lbl = NGUITools.AddWidget<UILabel>(go);
//        lbl.font = defaultFont;
//        lbl.text = go.name;
//        lbl.pivot = UIWidget.Pivot.Left;
//        lbl.cachedTransform.localPosition = new Vector3(fgPadding.x, 0f, 0f);
//        lbl.MakePixelPerfect();
//
//        // Add a collider
//        NGUITools.AddWidgetCollider(go);
//
//        // Add the popup list
//        UIPopupList list = go.AddComponent<UIPopupList>();
//        list.atlas = defaultAtlas;
//        list.font = defaultFont;
//        list.backgroundSprite = "";
//        list.highlightSprite = "";
//        list.padding = hlPadding;
//        if (isDropDown) list.textLabel = lbl;
//        for (int i = 0; i < 5; ++i) list.items.Add(isDropDown ? ("List Option " + i) : ("Menu Option " + i));
//
//        // Add the scripts
//        go.AddComponent<UIButton>().tweenTarget = sprite.gameObject;
//        go.AddComponent<UIButtonSound>();
//
//        return list;
//    }
//    #endregion //PopList
//
//    #region //ScrollBar
//    public static UIScrollBar CreateScrollBar(GameObject parent, string name, UIScrollBar.Direction direction)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//		GameObject	go = NGUITools.AddChild(parent);
//		go.name = name;
//
//		UISlicedSprite bg = NGUITools.AddWidget<UISlicedSprite>(go);
//		bg.name = "Background";
//		bg.depth = depth;
//		bg.atlas = defaultAtlas;
//		bg.transform.localScale = new Vector3(400f + bg.border.x + bg.border.z, 14f + bg.border.y + bg.border.w, 1f);
//		bg.MakePixelPerfect();
//
//		UISlicedSprite fg = NGUITools.AddWidget<UISlicedSprite>(go);
//		fg.name = "Foreground";
//        fg.atlas = defaultAtlas;
//
//		UIScrollBar sb = go.AddComponent<UIScrollBar>();
//		sb.background = bg;
//		sb.foreground = fg;
//        sb.direction = direction;
//		sb.barSize = 0.3f;
//		sb.scrollValue = 0.3f;
//		sb.ForceUpdate();
//
//		//if (mScrollCL)
//		{
//			NGUITools.AddWidgetCollider(bg.gameObject);
//			NGUITools.AddWidgetCollider(fg.gameObject);
//		}
//
//        return sb;
//    }
//
//    #endregion //ScrollBar
//
//    static void SetDefualtScale(UISprite sprite)
//    {
//        Texture tex = sprite.mainTexture;
//        sprite.transform.localScale = new Vector3(Mathf.Abs(sprite.outerUV.width * tex.width), Mathf.Abs(sprite.outerUV.height * tex.height), 1);
//    }
//
//    #endregion //Create UI
	
	#region //UI Resources
	
	public static GameObject GetWindowAsset(string filePath)
	{
		filePath = GetTrueFilePath(filePath, UIResourcesType.Window);
		GameObject window = null;
		if(windowResourcesList.ContainsKey(filePath))
			window = windowResourcesList[filePath].obj;
		
		if(window == null)
		{			
			try
			{
				AssetBundle asset = AssetBundle.CreateFromFile(filePath);
				if(asset != null)
				{
					GameObjectAsset assetInfo = new GameObjectAsset();
					assetInfo.filePath = filePath;
					assetInfo.obj = asset.mainAsset as GameObject;
					if(assetInfo.obj != null)
						windowResourcesList.Add(filePath, assetInfo);
					else
						assetInfo = null;
					asset.Unload(false);					
					window = assetInfo.obj;					
				}
			}
			catch(Exception e)
			{
				Debug.LogError(string.Format("UI窗口加载失败 ： {0}", filePath));
				Debug.LogException(e);
			}
			finally
			{
			}
		}
		
		return window;
	}
	
	public static GameObject GetWindowAsset<T>() where T : Window
	{
		return GetWindowAsset(typeof(T).Name);
	}
	
	public static string GetWindowAssetPath(GameObject windowAsset)
	{
		foreach(string filePath in windowResourcesList.Keys)
		{
			if(windowResourcesList[filePath].obj == windowAsset)
				return filePath;
		}
		
		return "";
	}
	
	public static UIAtlas GetAtlas(string filePath, string defualtPath)
	{
		if(string.IsNullOrEmpty(filePath) && string.IsNullOrEmpty(defualtPath))
			return null;
		
		filePath = GetTrueFilePath(filePath, UIResourcesType.Atlas);
		UIAtlas atlas = null;
		if(atlasList.ContainsKey(filePath))
			atlas = atlasList[filePath].atlas;
		
		if(atlas == null)
			LoaderManager.GetInstance().LoadAssetBunlde(filePath, LoaderManager.LoadTypeEnum.Atlas);
		
//		if(atlas == null)
//		{
//			try
//			{
//				AssetBundle asset = AssetBundle.CreateFromFile(filePath);
//				if(asset == null)
//				{
//					filePath = GetTrueFilePath(defualtPath, UIResourcesType.Atlas);
//					asset = AssetBundle.CreateFromFile(filePath);
//				}		
//				if(asset != null)
//				{		
//					AtlasAsset assetInfo = new AtlasAsset();
//					assetInfo.filePath = filePath;
//					assetInfo.atlas = (asset.mainAsset as GameObject).GetComponent<UIAtlas>();
//					if(assetInfo.atlas != null)
//						atlasList.Add(filePath, assetInfo);
//					asset.Unload(false);
//
//					atlas = assetInfo.atlas;
//				}
//			}
//			catch(Exception e)
//			{
//				Debug.LogError(string.Format("UI图集加载失败 ： {0}", filePath));
//				Debug.LogException(e);
//			}
//			finally
//			{
//			}
//		}
		
		return atlas;
	}
	
	public static UIAtlas GetAtlas(string filePath)
	{
		return GetAtlas(filePath, null);
	}
	
	public static string GetAtlasAssetPath(UIAtlas atlasAsset)
	{
		foreach(string filePath in atlasList.Keys)
		{
			if(atlasList[filePath].atlas == atlasAsset)
				return filePath;
		}
		
		return "";
	}
	
	public static void SetAtlas(AtlasAsset atlasAsset)
	{
		if(atlasAsset == null)
			return;
			
		if(atlasList.ContainsKey(atlasAsset.filePath))
			atlasList.Remove(atlasAsset.filePath);
		atlasList.Add(atlasAsset.filePath, atlasAsset);
		
		foreach(string filePath in cacheAtlasList.Keys)
		{
			if(string.Equals(filePath, atlasAsset.filePath))
			{
				UIAtlas atlas = atlasAsset.atlas;
				if(atlas != null)
				{
					AtlasRecordes recordes = cacheAtlasList[filePath];
					foreach(UISprite sprite in recordes.spriteList)
					{
						sprite.atlas = atlas;
					}
	//				foreach(UIMix mix in recordes.mixDefualtAtlasList)
	//				{
	//					mix.defaultAtlas = atlas;
	//				}
	//				foreach(UIMix mix in recordes.mixOtherAtlasList)
	//				{
	//					mix.atlasList.Add(atlas);
	//				}
					foreach(UIPopupList pop in recordes.popList)
					{
						pop.atlas = atlas;
					}
				}
			}
			
		}
		if(cacheAtlasList.ContainsKey(atlasAsset.filePath))
			cacheAtlasList.Remove(atlasAsset.filePath);
	}
	
	public static UIFont GetFont(string filePath, string defualtPath)
	{
		if(string.IsNullOrEmpty(filePath) && string.IsNullOrEmpty(defualtPath))
			return null;
		
		filePath = GetTrueFilePath(filePath, UIResourcesType.Font);
		UIFont font = null;
		if(fontList.ContainsKey(filePath))
			font = fontList[filePath].font;
		
		if(font == null)
			LoaderManager.GetInstance().LoadAssetBunlde(filePath, LoaderManager.LoadTypeEnum.Font);
		return font;
	}
	
	public static UIFont GetFont(string filePath)
	{
		return GetFont(filePath, null);
	}
	
	public static string GetFontAssetPath(UIFont fontAsset)
	{
		foreach(string filePath in fontList.Keys)
		{
			if(fontList[filePath].font == fontAsset)
				return filePath;
		}
		
		return "";
	}
	
	public static void SetFont(FontAsset fontAsset)
	{
		if(fontAsset == null)
			return;
			
		if(fontList.ContainsKey(fontAsset.filePath))
			fontList.Remove(fontAsset.filePath);
		fontList.Add(fontAsset.filePath, fontAsset);
		
		foreach(string filePath in cacheFontList.Keys)
		{
			if(string.Equals(filePath, fontAsset.filePath))
			{
				UIFont font = fontAsset.font;
				FontRecordes recordes = cacheFontList[filePath];
				foreach(UILabel label in recordes.labelList)
				{
					label.font = font;
				}
//				foreach(UIMix mix in recordes.mixDefualtFontList)
//				{
//					mix.defaultFont = font;
//				}
//				foreach(UIMix mix in recordes.mixOtherFontList)
//				{
//					mix.fontList.Add(font);
//				}
				foreach(UIPopupList pop in recordes.popList)
				{
					pop.font = font;
				}
			}
			
		}
		if(cacheFontList.ContainsKey(fontAsset.filePath))
			cacheFontList.Remove(fontAsset.filePath);
	}
	
	public static Material GetMaterial(string filePath, string defualtPath)
	{
		if(string.IsNullOrEmpty(filePath) && string.IsNullOrEmpty(defualtPath))
			return null;
		
		filePath = GetTrueFilePath(filePath, UIResourcesType.Material);
		Material material = null;
		if(materialList.ContainsKey(filePath))
			material = materialList[filePath].material;
		
		if(material == null)
			LoaderManager.GetInstance().LoadAssetBunlde(filePath, LoaderManager.LoadTypeEnum.Material);
		
		return material;
	}
	
	public static Material GetMaterial(string filePath)
	{
		return GetMaterial(filePath, null);
	}
	
	public static string GetMaterialAssetPath(Material materialAsset)
	{
		foreach(string filePath in materialList.Keys)
		{
			if(materialList[filePath].material == materialAsset)
				return filePath;
		}
		
		return "";
	}
	
	public static void SetMaterial(MaterialAsset materialAsset)
	{
		if(materialAsset == null)
			return;
		
		if(materialList.ContainsKey(materialAsset.filePath))
			materialList.Remove(materialAsset.filePath);
		materialList.Add(materialAsset.filePath, materialAsset);
		
		foreach(string filePath in cacheMaterialList.Keys)
		{
			if(string.Equals(filePath, materialAsset.filePath))
			{
				Material material = materialAsset.material;
				if(material != null)
				{
					MaterialRecordes recordes = cacheMaterialList[filePath];
					foreach(UITexture texture in recordes.textureList)
					{
						texture.material = material;
					}
				}
			}
		}
		if(cacheMaterialList.ContainsKey(materialAsset.filePath))
			cacheMaterialList.Remove(materialAsset.filePath);
	}
	
	public static GameObject GetEffect(string filePath, string defualtPath)
	{
		if(string.IsNullOrEmpty(filePath) && string.IsNullOrEmpty(defualtPath))
			return null;
		
		filePath = GetTrueFilePath(filePath, UIResourcesType.Effect);
		GameObject effect = null;
		if(effectList.ContainsKey(filePath))
			effect = effectList[filePath].obj;
		
		if(effect == null)
		{
			try
			{
				AssetBundle asset = AssetBundle.CreateFromFile(filePath);
				if(asset == null)
				{
					filePath = GetTrueFilePath(defualtPath, UIResourcesType.Effect);
					asset = AssetBundle.CreateFromFile(filePath);
				}
				if(asset != null)
				{
					GameObjectAsset assetInfo = new GameObjectAsset();
					assetInfo.filePath = filePath;
					assetInfo.obj = asset.mainAsset as GameObject;
					if(assetInfo.obj != null)
						effectList.Add(filePath, assetInfo);	
					asset.Unload(false);
					
					effect = assetInfo.obj;
				}
			}
			catch(Exception e)
			{
				Debug.LogError(string.Format("UI特效加载失败 ： {0}", filePath));
				Debug.LogException(e);
			}
			finally
			{
			}
		}
		
		return effect;
	}
	
	public static GameObject GetEffect(string filePath)
	{
		return GetEffect(filePath, null);
	}
	
	public static string GetEffectAssetPath(GameObject effectAsset)
	{
		foreach(string filePath in effectList.Keys)
		{
			if(effectList[filePath].obj == effectAsset)
				return filePath;
		}
		
		return "";
	}
	
	public static AudioClip GetAudio(string filePath, string defualtPath)
	{
		if(string.IsNullOrEmpty(filePath) && string.IsNullOrEmpty(defualtPath))
			return null;
		
		filePath = GetTrueFilePath(filePath, UIResourcesType.Sound);
		AudioClip audioClip = null;	
		if(soundsList.ContainsKey(filePath))
			audioClip = soundsList[filePath].audioClip;
		
		if(audioClip == null)
			LoaderManager.GetInstance().LoadAssetBunlde(filePath, LoaderManager.LoadTypeEnum.Sound);
		
		return audioClip;
	}
	
	public static AudioClip GetAudio(string filePath)
	{
		return GetAudio(filePath, null);
	}
	
	public static string GetSoundAssetPath(AudioClip soundAsset)
	{
		foreach(string filePath in soundsList.Keys)
		{
			if(soundsList[filePath].audioClip == soundAsset)
				return filePath;
		}
		
		return "";
	}
	
	public static void SetSound(SoundAsset soundAsset)
	{
		if(soundAsset == null)
			return;
		
		if(soundsList.ContainsKey(soundAsset.filePath))
			soundsList.Remove(soundAsset.filePath);
		soundsList.Add(soundAsset.filePath, soundAsset);
		
		foreach(string filePath in cacheSoundsList.Keys)
		{
			if(string.Equals(filePath, soundAsset.filePath))
			{
				AudioClip audioClip = soundAsset.audioClip;
				if(audioClip != null)
				{
					SoundsRecordes recordes = cacheSoundsList[filePath];
					foreach(UIButtonSound bsound in recordes.soundList)
					{
						bsound.audioClip = audioClip;
					}
				}
			}
		}
		if(cacheSoundsList.ContainsKey(soundAsset.filePath))
			cacheSoundsList.Remove(soundAsset.filePath);
	}
	
	public static string GetTrueFilePath(string filePath, UIResourcesType type)
	{	
		if(string.IsNullOrEmpty(filePath))
			return null;
		
		//扩展名转换
		string extension = Path.GetExtension(filePath);
		if(string.IsNullOrEmpty(extension))
			filePath = filePath + uiFitName;
		else if(extension != uiFitName)
			filePath = Path.ChangeExtension(filePath, uiFitName);
		
		//文件名含扩展名大小写
//		string fileName = Path.GetFileName(filePath).ToLower();
		
//		//目录检测
//		string folder = filePath.Substring(0, filePath.Length - fileName.Length);
//		if(string.IsNullOrEmpty(folder))
//		{		
//			switch(type)
//			{
//			case UIResourcesType.Window:
//				folder = GameResources.rootPath + windowFolder;
//				break;
//			case UIResourcesType.Atlas:
//				folder = GameResources.rootPath + atlasFolder;
//				break;
//			case UIResourcesType.Font:
//				folder = GameResources.rootPath + fontFolder;
//				break;
//			case UIResourcesType.Material:
//				folder = GameResources.rootPath + materialFolder;
//				break;
//			case UIResourcesType.Effect:
//				folder = GameResources.rootPath + effectFolder;
//				break;
//			case UIResourcesType.Sound:
//				folder = GameResources.rootPath + soundsFolder;
//				break;
//			default:
//				folder = GameResources.rootPath + uiRootFolder;
//				break;
//			}
//		}
//		else
//		{
//			if(!folder.StartsWith(GameResources.rootPath))
//			{
//				filePath = GameResources.rootPath + filePath;
//				folder = GameResources.rootPath + folder.TrimStart(fileTrimStart);
//			}
//		}
//			
		//本地真实文件检测
//		string[] files = Directory.GetFiles(folder, "*" + uiFitName, SearchOption.AllDirectories);
//        foreach (string file in files)
//        {
//			if(Path.GetFileName(file).ToLower() == fileName)
//			{
//				return file.Replace('\\', '/');
//			}
//		}
//		string folder = "";
//		switch(type)
//		{
//			case UIResourcesType.Window:
//				folder = GameResources.LocalPath + windowFolder;
//				if(filePath.Contains(windowFolder))
//					filePath = filePath.Substring(filePath.IndexOf(windowFolder));
//				break;
//			case UIResourcesType.Atlas:
//				folder = GameResources.LocalPath + atlasFolder;
//				break;
//			case UIResourcesType.Font:
//				folder = GameResources.LocalPath + fontFolder;
//				if(filePath.Contains(fontFolder))
//					filePath = filePath.Substring(filePath.IndexOf(fontFolder));
//				break;
//			case UIResourcesType.Material:
//				folder = GameResources.LocalPath + materialFolder;
//				if(filePath.Contains(materialFolder))
//					filePath = filePath.Substring(filePath.IndexOf(materialFolder));
//				break;
//			case UIResourcesType.Effect:
//				folder = GameResources.LocalPath + effectFolder;
//				break;
//			case UIResourcesType.Sound:
//				folder = GameResources.LocalPath + soundsFolder;
//				break;
//			default:
//				folder = GameResources.LocalPath + uiRootFolder;
//				break;
//		}
//		
//		filePath = (folder + fileName).Replace('\\', '/');
		
		switch(type)
		{
			case UIResourcesType.Window:
				filePath = GameResources.LocalPath + filePath.Substring(filePath.IndexOf(windowFolder));
				break;
			case UIResourcesType.Atlas:
				filePath = GameResources.LocalPath + filePath.Substring(filePath.IndexOf(atlasFolder));
				break;
			case UIResourcesType.Font:
				filePath = GameResources.LocalPath + filePath.Substring(filePath.IndexOf(fontFolder));
				break;
			case UIResourcesType.Material:
				filePath = GameResources.LocalPath + filePath.Substring(filePath.IndexOf(materialFolder));
				break;
			case UIResourcesType.Effect:
				filePath = GameResources.LocalPath + filePath.Substring(filePath.IndexOf(effectFolder));
				break;
			case UIResourcesType.Sound:
				filePath = GameResources.LocalPath + filePath.Substring(filePath.IndexOf(soundsFolder));
				break;
			default:
				filePath = GameResources.LocalPath + uiRootFolder + Path.GetFileName(filePath);
				break;
		}
		
		return filePath.ToLower();
	}
	
	public enum UIResourcesType
	{
		Window,
		Atlas,
		Font,
		Material,
		Effect,
		Sound,
	}
	
	public static bool GetSprite(string spritePath, out UIAtlas atlas, out UIAtlas.Sprite sprite)
	{		
		atlas = null;
		sprite = null;
		
		if(string.IsNullOrEmpty(spritePath))
			return false;		
		
		string[] fileStr = spritePath.Split('\\');
		if(fileStr.Length < 2)
			fileStr = spritePath.Split('/');
		if(fileStr.Length < 2)
			return false;
		
		string iconSpriteName =	Path.GetFileNameWithoutExtension(spritePath).Trim();
		string iconAltasName = fileStr[fileStr.Length - 2];
		bool find = false;
		
		atlas = GetAtlas(iconAltasName.ToLower());	
		if(atlas != null)
		{
			sprite = atlas.GetSprite(iconSpriteName);
			if(sprite != null)
				find = true;
		}
		
		return find;
	}
	
	#endregion //UI Resources
}

#else
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
using TConfig;

public class UIManager : MonoBehaviour
{
	static GameObject root;
    static Transform rootTrans;
    static string windowResourcesRootUrl = "GameResources/UI/Dep/Window/";
	
	static string fontFolder = "GameResources/UI/Base/Font/";
	static string atlasFolder = "GameResources/UI/Base/Atlas/";
	static string materialFolder = "GameResources/UI/Base/Material/";
	static string effectFolder = "GameResources/UI/Base/Effect/";
	static string soundsFolder = "GameResources/UI/Base/Sounds/";
	static string windowFolder = "GameResources/UI/Dep/Window/";
	
	public static Dictionary<string, GameObject> windowResourcesList = new Dictionary<string, GameObject>();
    public static Dictionary<string, Window> windows = new Dictionary<string, Window>();
	public static Dictionary<string, UIAtlas> atlasList = new Dictionary<string, UIAtlas>();
	public static Dictionary<string, UIFont> fontList = new Dictionary<string, UIFont>();
	public static Dictionary<string, Material> materialList = new Dictionary<string, Material>();
	public static Dictionary<string, GameObject> effectList = new Dictionary<string, GameObject>();
	public static Dictionary<string, AudioClip> soundsList = new Dictionary<string, AudioClip>();
	
	public static List<Window> openedSecondWindowList = new List<Window>();		//二级窗口列表
	public static List<Window> openedWindowListWhenOpen = new List<Window>();	//当窗口打开时，已打开的其他窗口列表
	public static bool IsFastKeyHiddeAllUI = false;								//快捷键关闭所有UI，用于无UI浏览场景或截屏
	
	public bool expanedWindows = true;
	//是否有全屏窗口打开
	public static bool fullScreenWindowOpen
	{
		get
		{
			foreach(Window window in windows.Values)
			{
				if(window.fullScreenWindow && window.Visible)
					return true;
			}
			
			return false;
		}
	}
	
	public static Window lastFocusWindow = null;
	public static Window currentFocusWindow = null;
	public static int screenLastWidth = 1024;
	public static int screenLastHeight = 768;
	
	public bool forcePerfectPixel = false;
	
	static public string fitName = ".uitresource";
	static UIManager instance;
	static public UIManager GetInst()
	{
		return instance;
	}
    void Awake()
    {
		instance = this;
		
        GameObject caObj = GameObject.Find("UI Camera");
		if(caObj != null)
			rootTrans = caObj.transform;
    }
	
	void OnDestroy()
	{
		windows.Clear();
		atlasList.Clear();
		fontList.Clear();
		materialList.Clear();
		effectList.Clear();
		soundsList.Clear();
	}
	
    void Update()
    {		
		if(screenLastWidth != Screen.width || screenLastHeight != Screen.height)
		{
			screenLastWidth = Screen.width;
			screenLastHeight = Screen.height;
			
			foreach(Window window in windows.Values)
			{
				window.OnScreenSizeChanged();
			}
		}
			
		if(forcePerfectPixel)
    		MakeAllUIPerfectPixel();
    }
	
	/// <summary>
	/// 窗口鼠标聚焦处理
	/// </summary>
	void LateUpdate()
	{		
		if(lastFocusWindow != currentFocusWindow)
		{
			if(lastFocusWindow != null)
				lastFocusWindow.OnLostFocus();
			
			if(currentFocusWindow != null)
				currentFocusWindow.OnFocus();
			
			lastFocusWindow = currentFocusWindow;
		}
	}
	
	//UI事件处理
	void OnGUI()
	{
		Event e = Event.current;
		if(e != null)
		{
			mIsKeyEvent = e.isKey;
			mIsMouseEvent = e.isMouse;

			if(e.type == EventType.MouseDown)
			{
				currentFocusWindow = UIManager.GetHoveredWindow();
			}
		}
		else
		{
			//当然消息为空
			mIsKeyEvent = false;
			mIsMouseEvent = false;
		}
	}
	
	public static void ReadyToLoadScene()
	{
		foreach(Window window in windows.Values)
			window.OnReadyToLoadScene();
	}
	
	public static void MakeAllUIPerfectPixel()
	{
		if (windowRoot != null)
        {
            for (int i = 0; i < windowRoot.childCount; i++)
            {
                Transform child = windowRoot.GetChild(i);
                MakeUINodePerfectPixelPosition(child, true);
            }
        }
	}

    public static void MakeUINodePerfectPixelPosition(Transform trans, bool toChildren)
    {
		if(trans == null)
			return;
		
        bool rePosition = true;
		if(LayerMask.LayerToName(trans.gameObject.layer) != "U2D")
		{
			rePosition = false;
			toChildren = false;
		}
		else
		{
	        if (trans.GetComponent<UIAnchor>() != null)
	            rePosition = false;
			
			UIWidget widget = trans.GetComponent<UIWidget>();
	        if (widget != null)
			{
	            rePosition = false;
				toChildren = false;
				widget.MakePositionPerfect();
			}
		}

        if (rePosition)
        {
            Vector3 pos = trans.localPosition;
            pos.x = Mathf.RoundToInt(pos.x);
            pos.y = Mathf.RoundToInt(pos.y);
//          pos.z = Mathf.CeilToInt(pos.z);

            trans.localPosition = pos;
        }
		
		if(toChildren)
		{
			if(trans.GetComponent<UITable>() != null)
				toChildren = false;
			if(trans.GetComponent<UIGrid>() != null)
				toChildren = false;
			if(trans.GetComponent<UIMix>() != null)
				toChildren = false;
		}
		
		if(toChildren)
		{
	        for (int i = 0; i < trans.childCount; i++)
	        {
	            Transform child = trans.GetChild(i);
	            MakeUINodePerfectPixelPosition(child, toChildren);
	        }
		}
    }
		
	public static GameObject uiRoot
	{
		get
		{
			if(root == null)
				root = GameObject.Find("UI Root (2D)");
			
			return root;
		}
	}
	
	public static Transform windowRoot
	{
		get
		{
			if(rootTrans == null)
				if(uiRoot != null)
					rootTrans = uiRoot.transform.FindChild("UI Camera");
			
			return rootTrans;
		}
	}
	
	#region //UI Event
	/// <summary>
	/// 检测是否为UI事件
	/// </summary>
	public static bool IsUIEvent
	{	
		get
		{
			return (IsPressDownUI 
				|| IsPressingUI 
				|| IsDraggingUI 
				|| IsPressUpUI 
				|| IsUIInput 
				|| fullScreenWindowOpen);
		}
	}
	
    /// <summary>
    /// 检测是否为悬停在UI上事件 
    /// </summary>
    public static bool IsMouseOnUI
    {
        get
        {
			if(fullScreenWindowOpen)
				return true;
			
            GameObject hoverObject = UICamera.hoveredObject;
			if(hoverObject == null)
				return false;
			else if(hoverObject.name.StartsWith("IgnoreUI-"))
				return false;
			
			Window window = GetHoveredWindow();
			if(window == null)
			{
				Debug.LogError("UI不能脱离窗口而存在！ UIControl：" + hoverObject.name, hoverObject);
				return false;
			}
			
			if(!window.Visible)
			{
				return false;
			}
			

			
			
            return true;
        }
    }
	
	/// <summary>
	/// 检测是否为刚按下UI事件
	/// </summary>
	public static bool IsPressDownUI
	{
		get
		{
			if(IsMouseDown && IsMouseOnUI)
				return true;
			
			return false;
		}
	}
	
	/// <summary>
	/// 检测否为UI按下状态
	/// </summary>
	public static bool IsPressingUI
	{
		get
		{
			if(IsMousePressed && GetPressedControl() != null)
				return true;
			
			return false;
		}
	}
	
	/// <summary>
	/// 检测是否为点击UI事件
	/// </summary>
	public static bool IsPressUpUI
	{
		get
		{			
			if(IsMouseUp && GetSelectedControl() != null)
				return true;			
			
			return false;
		}
	}
	
	/// <summary>
	/// 检测是否在拖拽UI
	/// </summary>
	public static bool IsDraggingUI
	{
		get
		{
			if(IsMousePressed && GetDragedControl() != null)
				return true;
			
			return false;
		}
	}
	
	/// <summary>
	/// 检测鼠标是否为刚按下状态
	/// </summary>
	public static bool IsMouseDown
	{
		get
		{
			return (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2));
		}
	}
	
	/// <summary>
	/// 检测鼠标是否为按下状态
	/// </summary>
	public static bool IsMousePressed
	{
		get
		{
			return (Input.GetMouseButton(0) || Input.GetMouseButton(1) || Input.GetMouseButton(2));
		}
	}
	
	// <summary>
	/// 检测鼠标是否为刚弹起状态
	/// </summary>
	public static bool IsMouseUp
	{
		get
		{
			return (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1) || Input.GetMouseButtonUp(2));
		}
	}
	
	/// <summary>
	/// 检测是否为按键信息
	/// </summary>
	private static bool mIsKeyEvent = false;
	public static bool IsKeyEvent
	{
		get
		{
			return mIsKeyEvent;
		}
	}
	
	/// <summary>
	/// 检测是否为鼠标事件
	/// </summary>
	private static bool mIsMouseEvent = false;
	public static bool IsMouseEvent
	{
		get
		{
			return mIsMouseEvent;
		}
	}
	
	/// <summary>
	/// 检测是否为UIInput事件
	/// </summary>
	public static bool IsUIInput
	{
		get
		{ 
			return (UICamera.inputHasFocus);
		}
	}
    #endregion  //UI Event
	
	
	
    #region //UI Init
    /// <summary>
    /// 初始化窗口管理类
    /// </summary>
    public void Init()
    {
//		Debug.Log("uimanager init");		
		LoadFont();
		LoadAtlas();
		LoadMaterial();
		LoadEffect();
		LoadSounds();
    }
	
	/// <summary>
	/// 加载字体资源
	/// </summary>
	static int fontCount = 0;
	static int fontLoadedCount = 0;
	static bool fontLoadOver = false;
	void LoadFont()
	{
		string folder = Directory.GetParent(Application.dataPath) + "/data/" + fontFolder;
		string[] files = Directory.GetFiles(folder,"*" + fitName , SearchOption.AllDirectories);
		fontCount = files.Length;
//		Debug.Log("Start to load font-----------------------------Sum count:" + fontCount);
        for(int i = 0; i < files.Length; i++)
		{
			string file = files[i];
//			Debug.Log(string.Format("Loading Font[{0}]:{1}", i, file));
			string fileName = Path.GetFileNameWithoutExtension(file).ToLower();			
			WWWObjectManager.GetInst().Load(fileName, file, LoadedFont);
		}
	}
	
	/// <summary>
	/// 加载图集资源
	/// </summary>
	static int atlasCount = 0;
	static int atlasLoadedCount = 0;
	static bool atlasLoadOver = false;
	void LoadAtlas()
	{
		string folder = Directory.GetParent(Application.dataPath) + "/data/" + atlasFolder;
		string[] files = Directory.GetFiles(folder, "*" +fitName, SearchOption.AllDirectories);
		atlasCount = files.Length;
//		Debug.Log("Start to load atlas-----------------------------Sum count:" + atlasCount);
        for(int i = 0; i < files.Length; i++)
		{
			string file = files[i];
//			Debug.Log(string.Format("Loading Atlas[{0}]:{1}", i, file));
			string fileName = Path.GetFileNameWithoutExtension(file).ToLower();
			
			WWWObjectManager.GetInst().Load(fileName, file, LoadedAtlas);
		}
	}
	
	/// <summary>
	/// 加载材质资源
	/// </summary>
	static int materialCount = 0;
	static int materialLoadedCount = 0;
	static bool materialLoadOver = false;
	void LoadMaterial()
	{
		string folder = Directory.GetParent(Application.dataPath) + "/data/" + materialFolder;
		string[] files = Directory.GetFiles(folder, "*" +fitName, SearchOption.AllDirectories);
		materialCount = files.Length;
//		Debug.Log("Start to load material-----------------------------Sum count:" + materialCount);
        for(int i = 0; i < files.Length; i++)
		{
			string file = files[i];
//			Debug.Log(string.Format("Loading Material[{0}]:{1}", i, file));
			string fileName = Path.GetFileNameWithoutExtension(file).ToLower();
			
			WWWObjectManager.GetInst().Load(fileName, file, LoadedMaterial);
		}
	}
	
	/// <summary>
	/// 加载特效资源
	/// </summary>
	static int effectCount = 0;
	static int effectLoadedCount = 0;
	static bool effectLoadOver = false;
	void LoadEffect()
	{
		string folder = Directory.GetParent(Application.dataPath) + "/data/" + effectFolder;
		string[] files = Directory.GetFiles(folder,  "*" +fitName, SearchOption.AllDirectories);
		effectCount = files.Length;
//		Debug.Log("Start to load effect-----------------------------Sum count:" + effectCount);
        for(int i = 0; i < files.Length; i++)
		{
			string file = files[i];
//			Debug.Log(string.Format("Loading Effect[{0}]:{1}", i, file));
			string fileName = Path.GetFileNameWithoutExtension(file).ToLower();
			
			WWWObjectManager.GetInst().Load(fileName, file, LoadedEffect);
		}
	}
	
	/// <summary>
	/// 加载音效资源
	/// </summary>
	static int soundCount = 0;
	static int soundLoadedCount = 0;
	static bool soundLoadOver = false;
	void LoadSounds()
	{
		string folder = Directory.GetParent(Application.dataPath) + "/data/" + soundsFolder;
		string[] files = Directory.GetFiles(folder,  "*" +fitName, SearchOption.AllDirectories);
		soundCount = files.Length;
//		Debug.Log("Start to load sound-----------------------------Sum count:" + soundCount);
        for(int i = 0; i < files.Length; i++)
		{
			string file = files[i];
//			Debug.Log(string.Format("Loading Sound[{0}]:{1}", i, file));
			string fileName = Path.GetFileNameWithoutExtension(file).ToLower();
			
			WWWObjectManager.GetInst().Load(fileName, file, LoadedSound);
		}
	}
	
	/// <summary>
	/// 完成一个字体资源加载
	/// parameter：参数值
	/// www：被加载对象
	/// </summary>
	void LoadedFont(object parameter, TMyFile www)
	{		
//		Debug.Log(string.Format("Loaded Font[{0}]:{1}", fontLoadedCount, www.url));
		GameObject prefab = www.obj as GameObject;		
		string fileName = (string)parameter;		
		
		if(fontList.ContainsKey(fileName))
			Debug.Log("UI资源名重复:" + www.url);
		else
			fontList.Add(fileName, prefab.GetComponent<UIFont>());
		
		fontLoadedCount++;
		if(fontLoadedCount == fontCount)
		{
			fontLoadOver = true;
			CheckBaseLoad();
		}
	}
	
	/// <summary>
	/// 完成一个图集资源加载
	/// parameter：参数值
	/// www：被加载对象
	/// </summary>
	void LoadedAtlas(object parameter, TMyFile www)
	{		
//		Debug.Log(string.Format("Loaded Atlas[{0}]:{1}", atlasLoadedCount, www.url));
		GameObject prefab = www.obj as GameObject;		
		string fileName = (string)parameter;
		if(atlasList.ContainsKey(fileName))
			Debug.Log("UI资源名重复:" + www.url);
		else
			atlasList.Add(fileName, prefab.GetComponent<UIAtlas>());
		
		atlasLoadedCount++;
		if(atlasLoadedCount == atlasCount)
		{
			atlasLoadOver = true;
			CheckBaseLoad();
		}
	}
	
	/// <summary>
	/// 完成一个材质资源加载
	/// parameter：参数值
	/// www：被加载对象
	/// </summary>
	void LoadedMaterial(object parameter, TMyFile www)
	{		
//		Debug.Log(string.Format("Loaded Material[{0}]:{1}", materialLoadedCount, www.url));
		Material prefab = www.obj as Material;		
		string fileName = (string)parameter;
		if(materialList.ContainsKey(fileName))
			Debug.Log("UI资源名重复:" + www.url);
		else
			materialList.Add(fileName, prefab);
		
		materialLoadedCount++;
		if(materialLoadedCount == materialCount)
		{
			materialLoadOver = true;
			CheckBaseLoad();
		}
	}
	
	/// <summary>
	/// 完成一个特效体资源加载
	/// parameter：参数值
	/// www：被加载对象
	/// </summary>
	void LoadedEffect(object parameter, TMyFile www)
	{		
//		Debug.Log(string.Format("Loaded Effect[{0}]:{1}", effectLoadedCount, www.url));
		GameObject prefab = www.obj as GameObject;		
		string fileName = (string)parameter;
		if(effectList.ContainsKey(fileName))
			Debug.Log("UI资源名重复:" + www.url);
		else
			effectList.Add(fileName, prefab);
		
		effectLoadedCount++;
		if(effectLoadedCount == effectCount)
		{
			effectLoadOver = true;
			CheckBaseLoad();
		}
	}
	
	/// <summary>
	/// 完成一个音效资源加载
	/// parameter：参数值
	/// www：被加载对象
	/// </summary>
	void LoadedSound(object parameter, TMyFile www)
	{		
//		Debug.Log(string.Format("Loaded Sound[{0}]:{1}", soundLoadedCount, www.url));
		AudioClip prefab = www.obj as AudioClip;		
		string fileName = (string)parameter;
		if(soundsList.ContainsKey(fileName))
			Debug.Log("UI资源名重复:" + www.url);
		else
			soundsList.Add(fileName, prefab);
		
		soundLoadedCount++;
		if(soundLoadedCount == soundCount)
		{
			soundLoadOver = true;
			CheckBaseLoad();
		}
	}
	
	/// <summary>
	/// 检测所有资源是否加载完毕
	/// </summary>
	void CheckBaseLoad()
	{
		if(fontLoadOver && atlasLoadOver && materialLoadOver && effectLoadOver && soundLoadOver)
			LoadWindow();
	}
	
	/// <summary>
	/// 加载窗口资源
	/// </summary>
	static int windowCount = 0;
	static int windowLoadedCount = 0;
	static bool windowLoadOver = false;
	void LoadWindow()
	{
		string folder = Directory.GetParent(Application.dataPath) + "/data/" + windowFolder;
		string[] files = Directory.GetFiles(folder, "*" +fitName, SearchOption.AllDirectories);
		windowCount = files.Length;
//		Debug.Log("Start to load windows-----------------------------Sum count:" + windowCount);
        for(int i = 0; i < files.Length; i++)
		{
			string file = files[i];
//			Debug.Log(string.Format("Loading Window[{0}]:{1}", i, file));
			string fileName = Path.GetFileNameWithoutExtension(file).ToLower(); 
//			string p = fileName.Substring(0,1);
//			string n = fileName.Substring(1,fileName.Length-1);
//			p = p.ToUpper();
//			fileName = p + n;
//			fileName=  fileName.Replace("window","Window");
			WWWObjectManager.GetInst().Load(fileName, file, LoadedWindow);
		}
	}
	
	/// <summary>
	/// 完成一个窗口资源加载
	/// parameter：参数值
	/// www：被加载对象
	/// </summary>
	void LoadedWindow(object parameter, TMyFile www)
	{
//		Debug.Log(string.Format("Loaded Window[{0}]:{1}", windowLoadedCount, www.url));
		GameObject prefab = www.obj as GameObject;
        if (prefab == null)
        {
            Debug.LogError("[UI]: The " + prefab.name + " resource has some problem ! (where : " + www.url + ")");
            return;
        }
		
		string windowName = (string)parameter;
		windowResourcesList.Add(windowName, prefab);
		
		InitWindow(windowName);
	}
	
	/// <summary>
	/// 实例化窗口
	/// windowName:窗口名
	public static void InitWindow(string windowName)
	{ 
        //CreatWindow
		windowName = windowName.ToLower();
		if(!windowResourcesList.ContainsKey(windowName))
		{
			Debug.Log(string.Format("没有{0}窗口资源！", windowName));
			return;
		}
		
		GameObject prefab = windowResourcesList[windowName];
        GameObject windowObj = MonoBehaviour.Instantiate(prefab) as GameObject;
		
        windowObj.name = windowName;
		Window window = windowObj.GetComponent<Window>();
		if(window==null)
		{
			Debug.LogError(string.Format("{0}:没有挂WINDOW脚本", windowName));
			DestroyImmediate(windowObj);
			return;
		}		
		if(windows.ContainsKey(windowName))
		{
			Debug.Log(string.Format("已经存在窗口：{0}！", windowName));
			DestroyImmediate(windowObj);
			return;
		}
		else
		{
			windows.Add(windowName, window);
		}
		
		Transform windowTrans = windowObj.transform;	
		windowTrans.parent = windowRoot;
		windowTrans.localPosition = Vector3.zero;
        windowTrans.localRotation = Quaternion.identity;
        windowTrans.localScale = Vector3.one;
		
		List<UIWidget> widgets = NGUITools.FindInChildren<UIWidget>(windowObj);
		foreach(UIWidget widget in widgets)
		{
			string srcPath = Path.GetFileNameWithoutExtension(widget.srcPath).ToLower();

			if(widget is UILabel)
			{
				UILabel label = widget as UILabel;
				label.font = GetFont(srcPath);
			}
			else if(widget is UISprite)
			{
				UISprite sprite = widget as UISprite;
				sprite.atlas = GetAtlas(srcPath);
			}
			else if(widget is UITexture)
			{
				UITexture texture = widget as UITexture;
				texture.material = GetMaterial(srcPath);
			}
		}
		
		List<UIMix> mixs = NGUITools.FindInChildren<UIMix>(windowObj);
		foreach(UIMix mix in mixs)
		{
			mix.defaultFont = GetFont(Path.GetFileNameWithoutExtension(mix.defaultFontSrcPath).ToLower());
			mix.defaultAtlas = GetAtlas(Path.GetFileNameWithoutExtension(mix.defaultAtlasSrcPath).ToLower());			
			
			for(int i = 0; i < mix.fontSrcPathList.Count; i++)
			{
				UIFont font = GetFont(Path.GetFileNameWithoutExtension(mix.fontSrcPathList[i]).ToLower());
				mix.fontList.Add(font); 
			}
			for(int i = 0; i < mix.atlasSrcPathList.Count; i++)
			{
				UIAtlas atlas = GetAtlas(Path.GetFileNameWithoutExtension(mix.atlasSrcPathList[i]).ToLower());
				mix.atlasList.Add(atlas); 
			}
		}
		
		List<UIPopupList> popList = NGUITools.FindInChildren<UIPopupList>(windowObj);
		foreach(UIPopupList pop in popList)
		{
			pop.font = GetFont(Path.GetFileNameWithoutExtension(pop.srcPath).ToLower());
		}
		
		List<UIButtonSound> bSounds = NGUITools.FindInChildren<UIButtonSound>(windowObj);
		foreach(UIButtonSound bsound in bSounds)
		{
			bsound.audioClip = GetAudio(bsound.srcPath.ToLower());
		}
		
//		window.Init();
		
       	windowObj.SetActiveRecursively(false);
		
		windowLoadedCount++;
		if(windowLoadedCount == windowCount)
		{
			windowLoadOver = true;
			MakeAllUIPerfectPixel();
		}
	}
	
	public static void ReLoadWindowResources(Window window)
	{
		GameObject windowObj = window.gameObject;
		List<UIWidget> widgets = NGUITools.FindInChildren<UIWidget>(windowObj);
		foreach(UIWidget widget in widgets)
		{
			string srcPath = Path.GetFileNameWithoutExtension(widget.srcPath).ToLower();

			if(widget is UILabel)
			{
				UILabel label = widget as UILabel;
				label.font = GetFont(srcPath);
			}
			else if(widget is UISprite)
			{
				UISprite sprite = widget as UISprite;
				sprite.atlas = GetAtlas(srcPath);
			}
			else if(widget is UITexture)
			{
				UITexture texture = widget as UITexture;
				texture.material = GetMaterial(srcPath);
			}
		}
		
		List<UIMix> mixs = NGUITools.FindInChildren<UIMix>(windowObj);
		foreach(UIMix mix in mixs)
		{
			mix.defaultFont = GetFont(Path.GetFileNameWithoutExtension(mix.defaultFontSrcPath).ToLower());
			mix.defaultAtlas = GetAtlas(Path.GetFileNameWithoutExtension(mix.defaultAtlasSrcPath).ToLower());			
			
			for(int i = 0; i < mix.fontSrcPathList.Count; i++)
			{
				UIFont font = GetFont(Path.GetFileNameWithoutExtension(mix.fontSrcPathList[i]).ToLower());
				mix.fontList.Add(font); 
			}
			for(int i = 0; i < mix.atlasSrcPathList.Count; i++)
			{
				UIAtlas atlas = GetAtlas(Path.GetFileNameWithoutExtension(mix.atlasSrcPathList[i]).ToLower());
				mix.atlasList.Add(atlas); 
			}
		}
		
		List<UIPopupList> popList = NGUITools.FindInChildren<UIPopupList>(windowObj);
		foreach(UIPopupList pop in popList)
		{
			pop.font = GetFont(Path.GetFileNameWithoutExtension(pop.srcPath).ToLower());
		}
		
		List<UIButtonSound> bSounds = NGUITools.FindInChildren<UIButtonSound>(windowObj);
		foreach(UIButtonSound bsound in bSounds)
		{
			bsound.audioClip = GetAudio(bsound.srcPath.ToLower());
		}
	}
	
	/// <summary>
	/// 获取已打开二级页面的个数
	/// </summary>
	public static int GetSecondOpenWindowCount()
	{
		return openedSecondWindowList.Count;
	}
	
	public static void CloseLastSecondOpenWindow()
	{
		if(openedSecondWindowList.Count > 0)
		{
			Window window = openedSecondWindowList[openedSecondWindowList.Count - 1];
			window.Close(true);
		}
	}
	
	public static void UpdateSecondWindowDepth()
	{
		for(int i = 0; i < openedSecondWindowList.Count; i++)
		{
//			openedSecondWindowList[i].SetDepth((900 - 50 * i) / 384.0f);	
			openedSecondWindowList[i].SetDepth(900 - 50 * i);
		}
	}

	/// <summary>
	/// 重新加载所有窗口
	/// </summary>
	public static void ReloadAllWindow()
	{		
		foreach(KeyValuePair<string, Window> window in windows)
		{
			window.Value.Clean();
//			GameObject windowObj = window.Value.gameObject;
//			DestroyImmediate(windowObj);
		}
		
		//清理UI相关记录
		CleanTemp();		
		
//		foreach(KeyValuePair<string, GameObject> window in windowResourcesList)
//		{
//			InitWindow(window.Key);
//		}
	}
	
	//清理UI相关记录
	static void CleanTemp()
	{
//		windows.Clear();
		openedSecondWindowList.Clear();
		lastFocusWindow = null;
//		windowLoadedCount = 0;
	}
    #endregion  //UI Init
	
	#region //Screen Postion
	/// <summary>
	/// 获取鼠标位置
	/// </summary>
	public static Vector3 GetMousePosition()
	{
		Vector3 pos = Input.mousePosition;
		
		return new Vector3(pos.x, UICamera.mainCamera.pixelHeight - pos.y, pos.z);
	}
	
	/// <summary>
	/// 获取控件在屏幕上的位置
	/// </summary>
	public static Vector3 GetControlScreenPosition(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlScreenPosition(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件在屏幕上的位置
	/// </summary>
	public static Vector3 GetControlScreenPosition(string windowName, string controlName)
	{
		return GetControlScreenPosition(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件在屏幕上的位置
	/// </summary>
	public static Vector3 GetControlScreenPosition(Window window, string controlName)
	{
		return GetControlScreenPosition(GetControl(window, controlName));
	}	
		
	/// <summary>
	/// 获取控件在屏幕上的位置
	/// </summary>
	public static Vector3 GetControlScreenPosition(GameObject control)
	{
		if(control == null)
			return Vector3.zero;
		
		//Camera uiCamera = NGUITools.FindCameraForLayer(control.layer);
		//if(uiCamera == null)
		Camera uiCamera = UICamera.mainCamera;
 
		Vector3 pos = uiCamera.WorldToScreenPoint(control.transform.position);
		return new Vector3(Mathf.RoundToInt(pos.x),  Mathf.RoundToInt(uiCamera.pixelHeight - pos.y), pos.z);
	}
	
	/// <summary>
	/// 获取控件中心点在屏幕上的位置
	/// </summary>
	/// </param>
	public static Vector3 GetControlCenterScreenPosition(GameObject control)
	{
		if(control == null)
			return Vector3.zero;
		
		Vector3 centerPos = GetControlScreenPosition(control) + GetControlCenterPixelOffset(control);
		centerPos.x  = Mathf.RoundToInt(centerPos.x);
		centerPos.y = Mathf.RoundToInt(centerPos.y);
		
		return centerPos;
	}
	
	/// <summary>
	/// 设置控件在屏幕上的位置
	/// </summary>
	public static void SetControlScreenPosition(GameObject control, float x, float y)
	{
		if(control == null)
			return;
		
		//Camera uiCamera = NGUITools.FindCameraForLayer(control.layer);
		//if(uiCamera == null)
		Camera uiCamera = UICamera.mainCamera;
		
		x = Mathf.RoundToInt(x);
		y = Mathf.RoundToInt(uiCamera.pixelHeight - y);
		float z = control.transform.position.z;		
		control.transform.position = uiCamera.ScreenToWorldPoint(new Vector3(x, y, z));
	}
	
	/// <summary>
    /// 设置控件屏幕坐标
    /// </summary>	
	public static void SetControlScreenPosition(GameObject control, Vector3 pos)
    {
        if(control == null)
			return;
		
//		Camera uiCamera = NGUITools.FindCameraForLayer(control.layer);
//		if(uiCamera == null)
		Camera	uiCamera = UICamera.mainCamera;
		
		pos.y = Mathf.RoundToInt(uiCamera.pixelHeight - pos.y);
		pos.x = Mathf.RoundToInt(pos.x);
		control.transform.position = uiCamera.ScreenToWorldPoint(pos);
    }
	#endregion //Scrren Postion
	

	#region //Window
	
	#region //Window Instance
    /// <summary>
    /// 获取窗口
    /// </summary>
    /// <param name="windowName">窗口名</param>
    /// <returns></returns>
    public static Window GetWindow(string windowName)
    {
		windowName = windowName.ToLower();
        if(windows.ContainsKey(windowName))
            return windows[windowName];
		
		GameObject windowObj = GameObject.Find(windowName);
		if(windowObj == null)
			windowObj = GetControlInChildren(uiRoot, windowName);
		
		if(windowObj != null)
		{
			Window window = windowObj.GetComponent<Window>();
			if(window != null)
			{
				windows.Add(windowName, window);				
				return window;
			}
		}

        return null;
    }
	
	public static T GetWindow<T>() where T : Window
	{
		return GetWindow<T>(typeof(T).Name);
	}
	
	public static T GetWindow<T>(string windowName) where T : Window
	{
		T window = GetWindow(windowName) as T;
		
		return window;
	}

    /// <summary>
    /// 向窗口管理类添加一个窗口，并给定一个名字
    /// </summary>
    /// <param name="windowTypeName">窗口资源名</param>
    /// <param name="windowName">资源名</param>
    public static Window AddWindow(string windowTypeName, string windowName)
    {
        if (GetWindow(windowName) != null)
        {
            Debug.LogError("[UI]: There is already have a window names " + windowTypeName + " !");
            return null;
        }

        Window windowType = GetWindow(windowTypeName);
        if (windowType == null)
        {
            Debug.LogError("[UI]: No " + windowTypeName + " resources !");
            return null;
        }

        GameObject windowObj = Instantiate(windowType.gameObject) as GameObject;
		windowObj.name = windowName;
		Window window = windowObj.GetComponent<Window>();  
		windows.Add(windowName, window);
		
		window.Init();
		windowObj.SetActiveRecursively(false);        
		
		return window;
    }

    static void InstantiateWindow(object parameter, TMyFile www)
    {
        GameObject prefab = www.obj as GameObject;
        //Release resources
        //www.obj.Unload(false);
        if (prefab == null)
        {
            Debug.LogError("[UI]: The " + prefab.name + " resource has some problem ! (where : " + www.url + ")");
            return;
        }
		
 
        //CreatWindow
        GameObject windowObj = MonoBehaviour.Instantiate(prefab) as GameObject;
		windowObj.SetActiveRecursively(true);
        string windowName = (string)parameter;
        windowObj.name = windowName;
		Window window = windowObj.GetComponent<Window>();
		if(window==null)
		{
			Debug.LogError(windowObj.name+ "没有挂WINDOW脚本"+www.url);
			return;
		}		
		windows.Add(windowName, window);
		
		Transform windowTrans = windowObj.transform;	
		windowTrans.parent = rootTrans;
		windowTrans.localPosition = Vector3.zero;
        windowTrans.localRotation = Quaternion.identity;
        windowTrans.localScale = Vector3.one;
		window.Init();
		
       	windowObj.SetActiveRecursively(false);
    }
	#endregion //Window Instance
	
	#region //Window Visible
    /// <summary>
    /// 检测窗口示显示状态
    /// </summary>
    /// <param name="windowName">窗口名</param>
    /// <returns>true显示、false隐藏 </returns>
    public static bool GetWindowVisible(string windowName)
    {
        Window window = GetWindow(windowName);
        if (window != null)
            return window.Visible;

        return false;
    }

    /// <summary>
    /// 隐藏显示窗口
    /// </summary>
    /// <param name="windowName">窗口名</param>
    /// <param name="Visible">true显示、false隐藏 </param>
    public static void SetWindowVisible(string windowName, bool Visible,bool byuser)
    {
        SetWindowVisible(GetWindow(windowName), Visible,byuser);
    }
	
	/// <summary>
	/// 设置窗口显示状态
	/// </summary>
	public static void SetWindowVisible(Window window, bool Visible,bool byuser )
	{
		if(window == null)
			return;
		
		if(Visible)
			window.Open(byuser);
		else
			window.Close(byuser);
	}

    /// <summary>
    /// 隐藏所有窗口
    /// </summary>
    public static void HideAllWindow()
    {
		openedWindowListWhenOpen.Clear();
        foreach (Window window in windows.Values)
        {
			if(window.Visible)
			{
				openedWindowListWhenOpen.Add(window);
            	window.Close(false);
			}
        }
    }
	
	public static void HideOtherWindows(Window window)
	{
		openedWindowListWhenOpen.Clear();
		foreach (Window win in windows.Values)
        {
			if(win.Visible && win != window )
			{
				openedWindowListWhenOpen.Add(window);
            	win.Close(false);
			}
			else if( win == window )
			{
				window.Open(false);
			}
        }
	}
	
	public static void HideOtherWindowsList(List<Window> window)
	{
		openedWindowListWhenOpen.Clear();
		foreach (Window win in windows.Values)
        {
			if( win.Visible )
			{
				for(int i=0; i < window.Count; ++i )
				{
					if( win != window[i] )
					{
						openedWindowListWhenOpen.Add(window[i]);
            			win.Close(false);
					}
				}
			}

			for(int i=0; i < window.Count; ++i )
			{
				if( win == window[i] )
				{
					window[i].Open(false);
				}		
			}
        }
	}
	
	public static void ReOpenAllHidenedWindow()
	{
        foreach (Window window in openedWindowListWhenOpen)
        {
			window.Open(false);
		}
	}
	#endregion //Window Visible
	
	#region //Window EventState
	/// <summary>
	/// Gets the selected window.
	/// </summary>
	/// <returns>
	/// The selected window.
	/// </returns>
	public static Window GetSelectedWindow()
	{
		GameObject selectedObject = UICamera.selectedObject;
		if(selectedObject == null)
			return null;
		
		return NGUITools.FindInParents<Window>(selectedObject);
	}
	
	/// <summary>
	/// Gets the name of the selected window.
	/// </summary>
	/// <returns>
	/// The selected window name.
	/// </returns>
	public static string GetSelectedWindowName()
	{
		Window selectedWindow = GetSelectedWindow();
		if(selectedWindow != null)
			return selectedWindow.name;
		
		return null;
	}
	
	/// <summary>
	/// Gets the hovered window.
	/// </summary>
	/// <returns>
	/// The hovered window.
	/// </returns>
	public static Window GetHoveredWindow()
	{
		GameObject hoveredObject = UICamera.hoveredObject;
		if(hoveredObject == null)
			return null;
		
		return NGUITools.FindInParents<Window>(hoveredObject);
	}
	
	/// <summary>
	/// Gets the name of the hovered window.
	/// </summary>
	/// <returns>
	/// The hovered window name.
	/// </returns>
	public static string GetHoveredWindowName()
	{
		Window hoveredWindow = GetHoveredWindow();
		if(hoveredWindow != null)
			return hoveredWindow.name;
		
		return null;
	}
	
	/// <summary>
	/// Gets the draged window.
	/// </summary>
	/// <returns>
	/// The draged window.
	/// </returns>
	public static Window GetDragedWindow()
	{
		GameObject dragedControl = GetDragedControl();
		if(dragedControl == null)
			return null;
		
		return NGUITools.FindInParents<Window>(dragedControl);
	}
	
	/// <summary>
	/// Gets the name of the draged window.
	/// </summary>
	/// <returns>
	/// The draged window name.
	/// </returns>
	public static string GetDragedWindowName()
	{
		Window window = GetDragedWindow();
		if(window == null)
			return null;
		
		return window.name;
	}
	#endregion //Window EventState	
	
	/// <summary>
	/// Gets the top second window.
	/// </summary>
	/// <returns>
	/// The top second window.
	/// </returns>
	public static Window GetTopSecondWindow()
	{
		int windowCount = openedSecondWindowList.Count;
		if(windowCount > 0)
			return openedSecondWindowList[windowCount - 1];
		
		return null;
	}
	
	/// <summary>
	/// Gets the name of the top second window.
	/// </summary>
	/// <returns>
	/// The top second window name.
	/// </returns>
	public static string GetTopSecondWindowName()
	{
		Window topSecondWindow = GetTopSecondWindow();
		if(topSecondWindow != null)
			return topSecondWindow.name;
		
		return null;
	}
	
	#endregion //Window
	
	#region //Panel
	
	
	#region //Panel Clipping
	/// <summary>
	/// 获取UI容器裁剪范围
	/// </summary>
	public static Vector4 GetPanelClipRange(string _panelName)
	{
		string windowName = _panelName.Split('_')[0];
        string panelName = _panelName.Substring(windowName.Length + 1);
		
		return GetPanelClipRange(GetControl(windowName, panelName));
	}
	
	/// <summary>
	/// 获取UI容器裁剪范围
	/// </summary>
	public static Vector4 GetPanelClipRange(string windowName, string panelName)
	{
		return GetPanelClipRange(GetControl(windowName, panelName));
	}
	
	/// <summary>
	/// 获取UI容器裁剪范围
	/// </summary>
	public static Vector4 GetPanelClipRange(Window window, string panelName)
	{
		return GetPanelClipRange(GetControl(window, panelName));
	}
	
	/// <summary>
	/// 获取UI容器裁剪范围
	/// </summary>
	public static Vector4 GetPanelClipRange(GameObject panelObj)
	{
		if(panelObj == null)
			return Vector4.zero;
		
		return GetPanelClipRange(panelObj.GetComponent<UIPanel>());
	}
	
	/// <summary>
	/// 获取UI容器裁剪范围
	/// </summary>
	public static Vector4 GetPanelClipRange(UIPanel panel)
	{
		if(panel != null)
			return panel.clipRange;
		
		return Vector4.zero;
	}
	
	/// <summary>
	/// 设置UI容器裁剪范围
	/// </summary>
	public static void SetPanelClipRange(string _panelName, Vector4 clipRange)
	{
		string windowName = _panelName.Split('_')[0];
        string panelName = _panelName.Substring(windowName.Length + 1);
		
		SetPanelClipRange(GetControl(windowName, _panelName), clipRange);
	}
	
	/// <summary>
	/// 设置UI容器裁剪范围
	/// </summary>
	public static void SetPanelClipRange(string windowName, string _panelName, Vector4 clipRange)
	{
		SetPanelClipRange(GetControl(windowName, _panelName), clipRange);
	}
	
	/// <summary>
	/// 设置UI容器裁剪范围
	/// </summary>
	public static void SetPanelClipRange(Window window, string _panelName, Vector4 clipRange)
	{
		SetPanelClipRange(GetControl(window, _panelName), clipRange);
	}
	
	/// <summary>
	/// 设置UI容器裁剪范围
	/// </summary>
	public static void SetPanelClipRange(GameObject panelObj, Vector4 clipRange)
	{
		SetPanelClipRange(panelObj.GetComponent<UIPanel>(), clipRange);
	}
	
	/// <summary>
	/// 设置UI容器裁剪范围
	/// </summary>
	public static void SetPanelClipRange(UIPanel panel, Vector4 clipRange)
	{
		if(panel == null)
			return;
		
		panel.clipRange = clipRange;
	}
	#endregion //Panel Clipping
		
		
	#endregion //Panel
	
	

    #region //Control Base

    #region //Control Instance
	/// <summary>
	///  获取窗口控件
	/// </summary>    
    public static GameObject GetControl(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
        return GetControl(GetWindow(windowName), controlName);
    }
	
	/// <summary>
	///  获取窗口控件
	/// </summary>    
    public static GameObject GetControl(string windowName, string controlName)
    {
        return GetControl(GetWindow(windowName), controlName);
    }
	
	/// <summary>
	///  获取窗口控件
	/// </summary> 
	public static GameObject GetControl(Window window, string controlName)
    {
		if(window == null)
			return null;
		
       	return GetControlInChildren(window.gameObject, controlName);
    }
	
	/// <summary>
	///  获取子控件
	/// </summary> 
	public static GameObject GetControlInChildren(GameObject obj, string controlName)
	{		
		if(obj == null)
			return null;

		Transform controlObj = null;
        string[] str = controlName.Split('/');
		Transform controlParentObj = obj.transform;
        for (int i = 0; i < str.Length; i++)
        {
            controlParentObj = GetControlInChildren(controlParentObj, str[i]);
            if (controlParentObj == null)
                return null;
			
			if(i == str.Length - 1)
             	controlObj = controlParentObj;
        }
		
		if(controlObj != null)
			return controlObj.gameObject;
		
		return null;
	}
	
	/// <summary>
	///  获取子控件
	/// </summary> 
    static Transform GetControlInChildren(Transform trans, string controlName)
    {	
		if(trans.name==controlName)
			return trans;
//		for(int i = 0; i < trans.childCount; i++)
//		{
//			Transform child = trans.GetChild(i);
//			if(child.gameObject.name == controlName)
//				return child;
//		}
		
		for(int i = 0; i < trans.childCount; i++)
		{
			Transform depChild = GetControlInChildren(trans.GetChild(i), controlName);
			if(depChild != null)
				return depChild;
		}
		
		return null;
    }
	
	/// <summary>
	/// 删除控件
	/// </summary>
	public void RemoveControl(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		RemoveControl(windowName, controlName);
	}
	
	/// <summary>
	/// 删除控件
	/// </summary>
	public void RemoveControl(string windowName, string controlName)
	{
		RemoveControl(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 删除控件
	/// </summary>
	public void RemoveControl(Window window, string controlName)
	{	
		RemoveControl(GetControl(window, controlName));
	}
	
	/// 删除控件
	/// </summary>
	public void RemoveControl(GameObject control)
	{
		DestroyImmediate(control);
	}
    #endregion  //Control Instance

    #region //Control Size
    /// <summary>
    /// 获取控件宽度
    /// </summary>
    public static float GetControlWidth(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlWidth(GetControl(windowName, controlName));		
    }
	
	/// <summary>
    /// 获取控件宽度
    /// </summary>
	public static float GetControlWidth(string windowName, string controlName)
	{
		return GetControlWidth(GetControl(windowName, controlName)); 		
	}
	
	/// <summary>
    /// 获取控件宽度
    /// </summary>
	public static float GetControlWidth(Window window, string controlName)
	{
		return GetControlWidth(GetControl(window, controlName)); 		
	}
	
	/// <summary>
    /// 获取控件宽度
    /// </summary>
	public static float GetControlWidth(GameObject control)
	{
		if(control == null)
			return 0;
		
		UILabel label = control.GetComponent<UILabel>();
		if(label != null)
			return label.pixelSize.x;
		
		UIMix mix = control.GetComponent<UIMix>();
		if(mix != null)
			return mix.pixelSize.x;
		
		return control.transform.localScale.x;
	}

    /// <summary>
    /// 设置控件宽度
    /// </summary>
    public static void SetControlWidth(string _controlName, float width)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlWidth(GetControl(windowName, controlName), width);		
    }
	
	/// <summary>
    /// 设置控件宽度
    /// </summary>
	public static void SetControlWidth(string windowName, string controlName, float width)
    {
		SetControlWidth(GetControl(windowName, controlName), width);
	}
	
	/// <summary>
    /// 设置控件宽度
    /// </summary>
	public static void SetControlWidth(Window window, string controlName, float width)
    {
		SetControlWidth(GetControl(window, controlName), width);
	}
	
	/// <summary>
    /// 设置控件宽度
    /// </summary>
	public static void SetControlWidth(GameObject control, float width)
	{
		if(control == null)
			return;
		
		Vector3 scale = control.transform.localScale;
		control.transform.localScale = new Vector3(width, scale.y, scale.z);
	}

    /// <summary>
    /// 获取控件高度
    /// </summary>
    public static float GetControlHeight(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlHeight(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件高度
    /// </summary>
    public static float GetControlHeight(string windowName, string controlName)
    {
        return GetControlHeight(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件高度
    /// </summary>
    public static float GetControlHeight(Window window, string controlName)
    {
        return GetControlHeight(GetControl(window, controlName));
    }
	
	/// <summary>
    /// 获取控件高度
    /// </summary>
    public static float GetControlHeight(GameObject control)
    {
		if(control == null)
			return 0;
		
		return control.transform.localScale.y;
    }

    /// <summary>
    /// 设置控件高度
    /// </summary>
    public static void SetControlHeight(string _controlName, float height)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlHeight(GetControl(windowName, controlName), height);
    }
	
	/// <summary>
    /// 设置控件高度
    /// </summary>
    public static void SetControlHeight(string windowName, string controlName, float height)
    {
		SetControlHeight(GetControl(windowName, controlName), height);
	}
	
	/// <summary>
    /// 设置控件高度
    /// </summary>
    public static void SetControlHeight(Window window, string controlName, float height)
    {
		SetControlHeight(GetControl(window, controlName), height);
	}
	
	/// <summary>
    /// 设置控件高度
    /// </summary>
    public static void SetControlHeight(GameObject control, float height)
    {
		if(control == null)
			return;
		
		Vector3 scale = control.transform.localScale;
		control.transform.localScale = new Vector3(scale.x, height, scale.z);
	}

    /// <summary>
    /// 获取控件尺寸
    /// </summary>
    public static Vector3 GetControlSize(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlSize(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件尺寸
    /// </summary>
    public static Vector3 GetControlSize(string windowName, string controlName)
    {
        return GetControlSize(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件尺寸
    /// </summary>
    public static Vector3 GetControlSize(Window window, string controlName)
    {
        return GetControlSize(GetControl(window, controlName));
    }
	
	/// <summary>
    /// 获取控件尺寸
    /// </summary>
    public static Vector3 GetControlSize(GameObject control)
    {
        if(control == null)
			return Vector3.zero;
		
		bool normalNode = true;
		Vector3 controlSize = Vector3.zero;
		
		if(normalNode)
		{
			UILabel label = control.GetComponent<UILabel>();
			if(label != null)
			{
				normalNode = false;
				controlSize = label.pixelSize;
			}
		}
		
		if(normalNode)
		{
			UIMix mix = control.GetComponent<UIMix>();
			if(mix != null)
			{
				normalNode = false;
				controlSize = mix.pixelSize;
			}
		}
		
		if(normalNode)
		{
			UISprite sprite = control.GetComponent<UISprite>();
			if(sprite != null)
			{
				normalNode = false;
				controlSize = control.transform.localScale;
			}
		}
		
		if(normalNode)
			controlSize = NGUIMath.CalculateRelativeWidgetBounds(control.transform).size;
		
		controlSize.x = Mathf.RoundToInt(controlSize.x);
		controlSize.y = Mathf.RoundToInt(controlSize.y);
		
		return controlSize;
    }

    /// <summary>
    /// 设置控件尺寸
    /// </summary>
    public static void SetControlSize(string _controlName, float width, float height)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlSize(GetControl(windowName, controlName), width, height);
    }
	
	/// <summary>
    /// 设置控件尺寸
    /// </summary>
    public static void SetControlSize(string windowName, string controlName, float width, float height)
    {
		SetControlSize(GetControl(windowName, controlName), width, height);
	}
	
	/// <summary>
    /// 设置控件尺寸
    /// </summary>
    public static void SetControlSize(Window window, string controlName, float width, float height)
    {
		SetControlSize(GetControl(window, controlName), width, height);
	}
	
	/// <summary>
    /// 设置控件尺寸
    /// </summary>
    public static void SetControlSize(GameObject control, float width, float height)
    {
		if(control == null)
			return;
		
		control.transform.localScale = new Vector3(width, height, control.transform.localScale.z);
	}
    #endregion //Control Size
	
	#region //Control Pivot
	/// <summary>
	/// 获取控件布局
	/// </summary>
	public static UIWidget.Pivot GetControlPivot(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlPivot(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件布局
	/// </summary>
	public static UIWidget.Pivot GetControlPivot(string windowName, string controlName)
	{
		return GetControlPivot(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件布局
	/// </summary>
	public static UIWidget.Pivot GetControlPivot(Window window, string controlName)
	{
		return GetControlPivot(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件布局
	/// </summary>
	public static UIWidget.Pivot GetControlPivot(GameObject control)
	{
		if(control == null)
			return UIWidget.Pivot.Center;
		
		UIWidget widget = control.GetComponent<UIWidget>();
		if(widget != null)
			return widget.pivot;
		
		UIMix mix = control.GetComponent<UIMix>();
		if(mix != null)
			return mix.pivot;
		
		return UIWidget.Pivot.Center;
	}
	
	/// <summary>
	/// 设置控件布局
	/// </summary>
	public static void SetControlPivot(string _controlName, UIWidget.Pivot pivot)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlPivot(GetControl(windowName, controlName), pivot);
	}
	
	/// <summary>
	/// 设置控件布局
	/// </summary>
	public static void SetControlPivot(string windowName, string controlName, UIWidget.Pivot pivot)
	{
		SetControlPivot(GetControl(windowName, controlName), pivot);
	}
	
	/// <summary>
	/// 设置控件布局
	/// </summary>
	public static void SetControlPivot(Window window, string controlName, UIWidget.Pivot pivot)
	{
		SetControlPivot(GetControl(window, controlName), pivot);
	}
	
	/// <summary>
	/// 设置控件布局
	/// </summary>
	public static void SetControlPivot(GameObject control, UIWidget.Pivot pivot)
	{
		if(control == null)
			return;
		
		UIWidget widget = control.GetComponent<UIWidget>();
		if(widget != null)
		{
			widget.pivot = pivot;
			return;
		}
		
		UIMix mix = control.GetComponent<UIMix>();
		if(mix != null)
		{
			mix.pivot = pivot;
			return;
		}
	}
	#endregion //Control Pivot
	
	#region //Control pivotOffset
	public static Vector3 GetControlCenterPixelOffset(GameObject control)
	{
		if(control == null)
			return Vector3.zero;
		
		Vector3 offset = NGUIMath.CalculateRelativeWidgetBounds(control.transform).center;
		Transform trans = control.transform;
		if(trans.childCount > 0)
			return new Vector3( offset.x, -offset.y, offset.z);
		else
		{
			Vector3 size = trans.localScale;
			return new Vector3(offset.x * size.x, -(offset.y * size.y), offset.z * size.z);
		}
	}
	#endregion //Control offset

    #region //Control Position
	/// <summary>
    /// 获取控件X坐标
    /// </summary>
	public static float GetControlPositionX(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlPositionX(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件X坐标
    /// </summary>
	public static float GetControlPositionX(string windowName, string controlName)
	{
		return GetControlPositionX(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件X坐标
    /// </summary>
	public static float GetControlPositionX(Window window, string controlName)
	{
		return GetControlPositionX(GetControl(window, controlName));
	}
	
	/// <summary>
    /// 获取控件X坐标
    /// </summary>
	public static float GetControlPositionX(GameObject control)
	{
		if(control == null)
			return 0;
		
		return control.transform.localPosition.x;
	}
	
    /// <summary>
    /// 设置控件X坐标
    /// </summary>
    public static void SetControlPositionX(string _controlName, float posX)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlPositionX(GetControl(windowName, controlName), posX);
    }
	
	/// <summary>
    /// 设置控件X坐标
    /// </summary>
    public static void SetControlPositionX(string windowName, string controlName, float posX)
    {
        SetControlPositionX(GetControl(windowName, controlName), posX);
	}
	
	/// <summary>
    /// 设置控件X坐标
    /// </summary>
    public static void SetControlPositionX(Window window, string controlName, float posX)
    {
        SetControlPositionX(GetControl(window, controlName), posX);
	}
	
	/// <summary>
    /// 设置控件X坐标
    /// </summary>
    public static void SetControlPositionX(GameObject control, float posX)
    {
        if(control == null)
			return;
		
		posX = Mathf.RoundToInt(posX);
		Vector3 position = control.transform.localPosition;
		control.transform.localPosition = new Vector3(posX, position.y, position.z);
    }
	
	/// <summary>
    /// 获取控件Y坐标
    /// </summary>
	public static float GetControlPositionY(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlPositionY(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件Y坐标
    /// </summary>
	public static float GetControlPositionY(string windowName, string controlName)
	{
		return GetControlPositionY(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件Y坐标
    /// </summary>
	public static float GetControlPositionY(Window window, string controlName)
	{
		return GetControlPositionY(GetControl(window, controlName));
	}
	
	/// <summary>
    /// 获取控件Y坐标
    /// </summary>
	public static float GetControlPositionY(GameObject control)
	{
		if(control == null)
			return 0;
		
		return control.transform.localPosition.y;
	}
	
    /// <summary>
    /// 设置控件Y坐标
    /// </summary>
    public static void SetControlPositionY(string _controlName, float posY)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlPositionY(GetControl(windowName, controlName), posY);
    }
	
	/// <summary>
    /// 设置控件Y坐标
    /// </summary>
    public static void SetControlPositionY(string windowName, string controlName, float posY)
    {
		SetControlPositionY(GetControl(windowName, controlName), posY);
    }
	
	/// <summary>
    /// 设置控件Y坐标
    /// </summary>
    public static void SetControlPositionY(Window window, string controlName, float posY)
    {
		SetControlPositionY(GetControl(window, controlName), posY);
    }
	
	/// <summary>
    /// 设置控件Y坐标
    /// </summary>
    public static void SetControlPositionY(GameObject control, float posY)
    {
       if(control == null)
			return;
		
		Vector3 position = control.transform.localPosition;
		posY = Mathf.RoundToInt(posY);
		control.transform.localPosition = new Vector3(position.x, posY, position.z);
    }
	
	/// <summary>
    /// 获取控件Z坐标
    /// </summary>
	public static float GetControlPositionZ(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlPositionZ(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件Z坐标
    /// </summary>
	public static float GetControlPositionZ(string windowName, string controlName)
	{
		return GetControlPositionZ(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件Z坐标
    /// </summary>
	public static float GetControlPositionZ(Window window, string controlName)
	{
		return GetControlPositionZ(GetControl(window, controlName));
	}
	
	/// <summary>
    /// 获取控件Z坐标
    /// </summary>
	public static float GetControlPositionZ(GameObject control)
	{
		if(control == null)
			return 0;
		
		return control.transform.localPosition.z;
	}
	
    /// <summary>
    /// 设置控件Z坐标
    /// </summary>
    public static void SetControlPositionZ(string _controlName, float posZ)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlPositionZ(GetControl(windowName, controlName), posZ);
    }
	
	/// <summary>
    /// 设置控件Z坐标
    /// </summary>
    public static void SetControlPositionZ(string windowName, string controlName, float posZ)
    {
		SetControlPositionZ(GetControl(windowName, controlName), posZ);
    }
	
	/// <summary>
    /// 设置控件Z坐标
    /// </summary>
    public static void SetControlPositionZ(Window window, string controlName, float posZ)
    {
       SetControlPositionZ(GetControl(window, controlName), posZ);
    }
	
	/// <summary>
    /// 设置控件Z坐标
    /// </summary>
    public static void SetControlPositionZ(GameObject control, float posZ)
    {
       if(control == null)
			return;
		
		Vector3 position = control.transform.localPosition;
		control.transform.localPosition = new Vector3(position.x, position.y, posZ);
    }
	
	/// <summary>
    /// 获取控件坐标
    /// </summary>
	public static Vector3 GetControlPosition(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlPosition(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件坐标
    /// </summary>
	public static Vector3 GetControlPosition(string windowName, string controlName)
    {
        return GetControlPosition(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件坐标
    /// </summary>
	public static Vector3 GetControlPosition(Window window, string controlName)
    {
        return GetControlPosition(GetControl(window, controlName));
    }
	
	/// <summary>
    /// 获取控件坐标
    /// </summary>
	public static Vector3 GetControlPosition(GameObject control)
    {
        if(control == null)
			return Vector3.zero;
		
		return control.transform.localPosition;
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(string _controlName, float posX, float posY)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

		SetControlPosition(GetControl(windowName, controlName), posX, posY);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(string windowNmae, string controlName, float posX, float posY)
    {
		SetControlPosition(GetControl(windowNmae, controlName), posX, posY);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(Window window, string controlName, float posX, float posY)
    {
		SetControlPosition(GetControl(window, controlName), posX, posY);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(GameObject control, float posX, float posY)
    {
        if(control == null)
			return;
		
		posX = Mathf.RoundToInt(posX);
		posY = Mathf.RoundToInt(posY);
		
		control.transform.localPosition = new Vector3(posX, posY, control.transform.localPosition.z);
    }

    /// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(string _controlName, float posX, float posY, float posZ)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

		SetControlPosition(GetControl(windowName, controlName), posX, posY, posZ);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(string windowNmae, string controlName, float posX, float posY, float posZ)
    {
		SetControlPosition(GetControl(windowNmae, controlName), posX, posY, posZ);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(Window window, string controlName, float posX, float posY, float posZ)
    {
		SetControlPosition(GetControl(window, controlName), posX, posY, posZ);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(GameObject control, float posX, float posY, float posZ)
    {
        if(control == null)
			return;
		
		posX = Mathf.RoundToInt(posX);
		posY = Mathf.RoundToInt(posY);
		
		control.transform.localPosition = new Vector3(posX, posY, posZ);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(string _controlName, Vector3 pos)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

		SetControlPosition(GetControl(windowName, controlName), pos);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(string windowNmae, string controlName, Vector3 pos)
    {
		SetControlPosition(GetControl(windowNmae, controlName), pos);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(Window window, string controlName, Vector3 pos)
    {
		SetControlPosition(GetControl(window, controlName), pos);
    }
	
	/// <summary>
    /// 设置控件坐标
    /// </summary>	
	public static void SetControlPosition(GameObject control, Vector3 pos)
    {
        if(control == null)
			return;
		
		pos.x = Mathf.RoundToInt(pos.x);
		pos.y = Mathf.RoundToInt(pos.y);
		
		control.transform.localPosition = pos;
    }
    #endregion //Control Position

    #region //Control Sprite And Resources
    /// <summary>
    /// 获取控件SpriteName
    /// </summary>
    public static string GetControlSpriteName(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlSpriteName(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件SpriteName
    /// </summary>
    public static string GetControlSpriteName(string windowName, string controlName)
    {
		return GetControlSpriteName(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件SpriteName
    /// </summary>
    public static string GetControlSpriteName(Window window, string controlName)
    {
		return GetControlSpriteName(GetControl(window, controlName));
    }
	
	/// <summary>
    /// 获取控件SpriteName
    /// </summary>
    public static string GetControlSpriteName(GameObject control)
    {
		if(control == null)
			return null;
		
        UISprite sprite = control.GetComponent<UISprite>();
		if(sprite == null)
			return null;
		
		return sprite.spriteName;
    }
	
	/// <summary>
    /// 设置控件SpriteName
    /// </summary>
	public static void SetControlSpriteName(string _controlName, string spriteName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlSpriteName(GetControl(windowName, controlName), spriteName);
    }
	
	/// <summary>
    /// 设置控件SpriteName
    /// </summary>
	public static void SetControlSpriteName(string windowName, string controlName, string spriteName)
    {
        SetControlSpriteName(GetControl(windowName, controlName), spriteName);
    }
	
	/// <summary>
    /// 设置控件SpriteName
    /// </summary>
	public static void SetControlSpriteName(Window window, string controlName, string spriteName)
    {
        SetControlSpriteName(GetControl(window, controlName), spriteName);
    }
	
	/// <summary>
    /// 设置控件SpriteName
    /// </summary>
	public static void SetControlSpriteName(GameObject control, string spriteName)
    {
        if(control == null)
			return;
		
		UISprite sprite = control.GetComponent<UISprite>();
		if(sprite == null)
			return;
		
		sprite.spriteName = spriteName;
    }
	
	/// <summary>
	/// 获取控件资源图片集名字
	/// </summary>
	public static string GetControlAtlasName(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlAtlasName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件资源图片集名字
	/// </summary>
	public static string GetControlAtlasName(string windowName, string controlName)
	{
		return GetControlAtlasName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件资源图片集名字
	/// </summary>
	public static string GetControlAtlasName(Window window, string controlName)
	{
		return GetControlAtlasName(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件资源图片集名字
	/// </summary>
	public static string GetControlAtlasName(GameObject control)
	{
		UIAtlas atlas = GetControlAtlas(control);
		if(atlas == null)
			return null;
		
		return atlas.name;
	}
	
	/// <summary>
	/// 获取控件资源图片集
	/// </summary>
	public static UIAtlas GetControlAtlas(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlAtlas(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件资源图片集
	/// </summary>
	public static UIAtlas GetControlAtlas(string windowName, string controlName)
	{
		return GetControlAtlas(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件资源图片集
	/// </summary>
	public static UIAtlas GetControlAtlas(Window window, string controlName)
	{
		return GetControlAtlas(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件资源图片集
	/// </summary>
	public static UIAtlas GetControlAtlas(GameObject control)
	{
		if(control == null)
			return null;
		
		UISprite sprite = control.GetComponent<UISprite>();
		if(sprite == null)
			return null;
		
		return sprite.atlas;
	}
	
	/// <summary>
    /// 设置控件资源图片集
    /// </summary>
    public static void SetControlAtlas(string _controlName, UIAtlas atlas)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
        SetControlAtlas(GetControl(windowName, controlName), atlas);
    }
	
	/// <summary>
    /// 设置控件资源图片集
    /// </summary>
    public static void SetControlAtlas(string windowName, string controlName, UIAtlas atlas)
    {
       SetControlAtlas(GetControl(windowName, controlName), atlas);
    }
	
	/// <summary>
    /// 设置控件资源图片集
    /// </summary>
    public static void SetControlAtlas(Window window, string controlName, UIAtlas atlas)
    {
       SetControlAtlas(GetControl(window, controlName), atlas);
    }
	
	/// <summary>
    /// 设置控件资源图片集
    /// </summary>
    public static void SetControlAtlas(GameObject control, UIAtlas atlas)
    {
       if(control == null)
			return;
		
		UISprite sprite = control.GetComponent<UISprite>();
		if(sprite == null)
			return;
		
		sprite.atlas = atlas;
    }
	
	/// <summary>
	/// 获取控件材质球名字
	/// </summary>
	public static string GetControlMaterialName(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlMaterialName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件材质球名字
	/// </summary>
	public static string GetControlMaterialName(string windowName, string controlName)
	{
		return GetControlMaterialName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件材质球名字
	/// </summary>
	public static string GetControlMaterialName(Window window, string controlName)
	{
		return GetControlMaterialName(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件材质球名字
	/// </summary>
	public static string GetControlMaterialName(GameObject control)
	{
		Material material = GetControlMaterial(control);
		if(material == null)
			return null;
		
		return material.name;
	}
	
	/// <summary>
	/// 获取控件材质球
	/// </summary>
	public static Material GetControlMaterial(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlMaterial(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件材质球
	/// </summary>
	public static Material GetControlMaterial(string windowName, string controlName)
	{
		return GetControlMaterial(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件材质球
	/// </summary>
	public static Material GetControlMaterial(Window window, string controlName)
	{
		return GetControlMaterial(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件材质球
	/// </summary>
	public static Material GetControlMaterial(GameObject control)
	{
		if(control == null)
			return null;

		UIWidget widget = control.GetComponent<UIWidget>();
		if(widget == null)
			return null;
		
		return widget.material;
	}
	
	/// <summary>
	/// 设置控件材质球
	/// </summary>
	public static void SetControlMaterial(string _controlName, Material material)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlMaterial(GetControl(windowName, controlName), material);
	}
	
	/// <summary>
	/// 设置控件材质球
	/// </summary>
	public static void SetControlMaterial(string windowName, string controlName, Material material)
	{
		SetControlMaterial(GetControl(windowName, controlName), material);
	}
	
	/// <summary>
	/// 设置控件材质球
	/// </summary>
	public static void SetControlMaterial(Window window, string controlName, Material material)
	{
		SetControlMaterial(GetControl(window, controlName), material);
	}
	
	/// <summary>
	/// 设置控件材质球
	/// </summary>
	public static void SetControlMaterial(GameObject control, Material material)
	{
		if(control == null)
			return;
		
		UIWidget widget = control.GetComponent<UIWidget>();
		if(widget == null)
			return;
		
		widget.material = material;
	}
    #endregion  //Control Sprite And Resources

    #region //Control Color	
    /// <summary>
    /// 设置控件颜色
    /// </summary>
    public static void SetControlColor(string _controlName, Color color)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlColor(GetControl(windowName, controlName), color);
    }
	
	/// <summary>
    /// 设置控件颜色
    /// </summary>
    public static void SetControlColor(string windowName, string controlNanme, Color color)
    {
        SetControlColor(GetControl(windowName, controlNanme), color);
    }
	
	/// <summary>
    /// 设置控件颜色
    /// </summary>
    public static void SetControlColor(Window window, string controlNanme, Color color)
    {
        SetControlColor(GetControl(window, controlNanme), color);
    }
	
	/// <summary>
    /// 设置控件颜色
    /// </summary>
    public static void SetControlColor(GameObject control, Color color)
    {
        if(control == null)
			return;
		
		UIWidget widget = control.GetComponent<UIWidget>();
		if(widget != null)
			widget.color = color;
		else
		{
			UIMix mix = control.GetComponent<UIMix>();
			if(mix != null)
				mix.color = color;
		}
    }

    /// <summary>
    /// 设置控件透明度
    /// </summary>
    public static void SetControlAlpha(string _controlName, float alpha, bool toChildren)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

       	SetControlAlpha(GetControl(windowName, controlName), alpha, toChildren);
    }
	
	/// <summary>
	/// 设置控件透明度
	/// </summary>
	public static void SetControlAlpha(string windowName, string controlName, float alpha, bool toChildren)
	{
		SetControlAlpha(GetControl(windowName, controlName), alpha, toChildren);
	}
	
	/// <summary>
	/// 设置控件透明度
	/// </summary>
	public static void SetControlAlpha(Window window, string controlName, float alpha, bool toChildren)
	{
		SetControlAlpha(GetControl(window, controlName), alpha, toChildren);
	}
	
	/// <summary>
	/// 设置控件透明度
	/// </summary>
	public static void SetControlAlpha(GameObject control, float alpha, bool toChildren)
	{
		if(control == null)
			return;
		
		SetControlAlpha(control.transform, alpha, toChildren);
	}
	
	//设置控件透明度
	public static void SetControlAlpha(Transform trans, float alpha, bool toChildren)
	{
		SetControlAlpha(trans, alpha, toChildren, false);
	}
	
	//设置控件透明度
	public static void SetControlAlpha(Transform trans, float alpha, bool toChildren, bool windowAlpha)
	{
		UIWidget widget = trans.GetComponent<UIWidget>();
		if(widget != null)
		{			
			UIAlaphaTweenRecord record = trans.GetComponent<UIAlaphaTweenRecord>();
			
			if(!windowAlpha || record == null)
				widget.alpha = alpha;
			else
				widget.alpha = record.oldAlpha * alpha;
			
			if(widget is UILabel)
			{
				UILabel label = widget as UILabel;
				if(label.effectStyle != UILabel.Effect.None)
				{
					Color effectColor = label.effectColor;
					if(!windowAlpha || record == null)
						effectColor.a = alpha;
					else
						effectColor.a = record.effectColor.a * alpha;
					
					label.effectColor = effectColor;
				}
			}
		}
		
		UIMix mix = trans.GetComponent<UIMix>();
		if(mix != null)
		{
			toChildren = false;
			
			UIAlaphaTweenRecord record = trans.GetComponent<UIAlaphaTweenRecord>();
			if(!windowAlpha || record == null)
				mix.alpha = alpha;
			else
				mix.alpha = record.oldAlpha * alpha;
			
			if(mix.effectStyle != UILabel.Effect.None)
			{
				Color effectColor = mix.effectColor;
				if(!windowAlpha || record == null)
					effectColor.a = alpha;
				else
					effectColor.a = record.effectColor.a * alpha;
				mix.effectColor = effectColor;
			}
		}
		
		if(toChildren)
		{
			for(int i = 0; i < trans.childCount; i++)
				SetControlAlpha(trans.GetChild(i), alpha, toChildren);
		}
	}
		
	//记录控件默认透明度
	public static void RecordAlpha(Transform trans)
	{
		UIWidget widget = trans.GetComponent<UIWidget>();
		if(widget != null)
		{			
			UIAlaphaTweenRecord record = trans.GetComponent<UIAlaphaTweenRecord>();
			if(record == null)
				record = trans.gameObject.AddComponent<UIAlaphaTweenRecord>();
				
			record.oldAlpha = widget.alpha;				
			if(widget is UILabel)
			{
				UILabel label = widget as UILabel;
				if(label.effectStyle != UILabel.Effect.None)
				{
					record.effectStyle = label.effectStyle;
					record.effectColor = label.effectColor;
				}
			}
		}
		
		UIMix mix = trans.GetComponent<UIMix>();
		if(mix != null)
		{
			UIAlaphaTweenRecord record = trans.GetComponent<UIAlaphaTweenRecord>();
			if(record == null)
				record = trans.gameObject.AddComponent<UIAlaphaTweenRecord>();
			
			record.oldAlpha = mix.alpha;
			
			if(mix.effectStyle != UILabel.Effect.None)
			{
				record.effectStyle = mix.effectStyle;
				record.effectColor = mix.effectColor;
			}
		}
		
		for(int i = 0; i < trans.childCount; i++)
			RecordAlpha(trans.GetChild(i));;
	}
	
	//恢复控件默认透明度
	public static void RevertAlpha(Transform trans)
	{
		UIWidget widget = trans.GetComponent<UIWidget>();
		if(widget != null)
		{
			UIAlaphaTweenRecord record = trans.GetComponent<UIAlaphaTweenRecord>();
			if(record != null)
			{
				widget.alpha = record.oldAlpha;
			
				if(widget is UILabel)
				{
					UILabel label = widget as UILabel;
					if(label.effectStyle != UILabel.Effect.None)
					{
						label.effectStyle = record.effectStyle;
						label.effectColor = record.effectColor;
					}
				}
			}
		}
		
		UIMix mix = trans.GetComponent<UIMix>();
		if(mix != null)
		{
			UIAlaphaTweenRecord record = trans.GetComponent<UIAlaphaTweenRecord>();
			if(record != null)
			{
				if(mix.effectStyle != UILabel.Effect.None)
				{
					mix.alpha = record.oldAlpha;
					mix.effectStyle = record.effectStyle;
					mix.effectColor = record.effectColor;
				}
			}
		}
		
		for(int i = 0; i < trans.childCount; i++)
			RevertAlpha(trans.GetChild(i));
	}
    #endregion  //Control Color
	
	#region //Control Normal
	/// <summary>
	/// 检测控件是否为正常状态
	/// </summary>
	public static bool IsControlNormalState(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return IsControlNormalState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件状态是否为正常状态
	/// </summary>
	public static bool IsControlNormalState(string windowName, string controlName)
	{
		return IsControlNormalState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件状态是否为正常状态
	/// </summary>
	public static bool IsControlNormalState(Window window, string controlName)
	{
		return IsControlNormalState(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件状态是否为正常状态
	/// </summary>
	public static bool IsControlNormalState(GameObject control)
	{
		if(control == null)
			return false;
		
		if(IsControlHoveredState(control))
			return false;
		if(IsControlDragedState(control))
			return false;
		if(IsControlPressedState(control))
			return false;
		if(IsControlSelectedState(control))
			return false;
		
		//Checked
		if(IsControlCheckedState(control))
			return false;
		
		return true;
	}
	
	/// <summary>
	/// 设置控件状态为正常状态
	/// </summary>
	public static void SetControlStateToNormal(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlStateToNormal(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 设置控件状态为正常状态
	/// </summary>
	public static void SetControlStateToNormal(string windowName, string contorlName)
	{
		SetControlStateToNormal(GetControl(windowName, contorlName));
	}
	
	/// <summary>
	/// 设置控件状态为正常状态
	/// </summary>
	public static void SetControlStateToNormal(Window window, string contorlName)
	{
		SetControlStateToNormal(GetControl(window, contorlName));
	}
	
	/// <summary>
	/// 设置控件状态为正常状态
	/// </summary>
	public static void SetControlStateToNormal(GameObject contorl)
	{
		if(contorl == null)
			return;
		
		//Hover & Drag can't notify.

		SetControlPresseState(contorl, false);
		
		SetControlSelectState(contorl, false);
		
		//Checked
		SetControlCheckState(contorl, false);
		
		UIImageButton umb = contorl.GetComponent<UIImageButton>();
		if(umb != null)
		{
			if(umb.target != null)
				umb.target.spriteName = umb.normalSprite;
		}
	}
	#endregion //Control Normal
	
	#region //Control Hover
	/// <summary>
	/// 获取当前被鼠标悬停的控件
	/// </summary>
	public static GameObject GetHoveredControl()
	{
		return UICamera.hoveredObject;
	}
	
	/// <summary>
	/// 获取当前被鼠标悬停的控件的名字
	/// </summary>
	public static string GetHoveredControlName()
	{
		GameObject hoveredObject = GetHoveredControl();
		if(hoveredObject != null)
			return hoveredObject.name;
		
		return null;
	}
	
	/// <summary>
	/// 检测控件是否为被鼠标悬停状态
	/// </summary>
	public static bool IsControlHoveredState(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return IsControlHoveredState(GetControl(windowName, controlName));
    }
	
	/// <summary>
	/// 检测控件是否为被鼠标悬停状态
	/// </summary>
	public static bool IsControlHoveredState(string windowName, string controlName)
    {
       return IsControlHoveredState(GetControl(windowName, controlName));
    }
	
	/// <summary>
	/// 检测控件是否为被鼠标悬停状态
	/// </summary>
	public static bool IsControlHoveredState(Window window, string controlName)
    {
       return IsControlHoveredState(GetControl(window, controlName));
    }
	
	/// <summary>
	/// 检测控件是否为被鼠标悬停状态
	/// </summary>
	public static bool IsControlHoveredState(GameObject control)
    {
		if(control == null)
			return false;
		
       	return (control == GetHoveredControl());
    }
	#endregion //Control Hover
	
	#region //Control Drag
	/// <summary>
	/// 获取正被鼠标Draed的控件
	/// </summary>
	public static GameObject GetDragedControl()
	{
		return UICamera.dragedObject;
	}
	
	/// <summary>
	/// 获取正被鼠标Draed的控件
	/// </summary>
	public static string GetDragedControlName()
	{
		GameObject dragedObject = GetDragedControl();
		if(dragedObject == null)
			return null;
		
		return dragedObject.name;
	}
	
	/// <summary>
	/// 检测控件是否为被Draged状态
	/// </summary>
	public static bool IsControlDragedState(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return IsControlDragedState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为被Draged状态
	/// </summary>
	public static bool IsControlDragedState(string windowName, string controlName)
	{
		return IsControlDragedState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为被Draged状态
	/// </summary>
	public static bool IsControlDragedState(Window window, string controlName)
	{
		return IsControlDragedState(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为被Draged状态
	/// </summary>
	public static bool IsControlDragedState(GameObject control)
	{
		if(control == null)
			return false;
		
		return (control == GetDragedControl());
	}
	#endregion //Control Drag
	
	#region //Control Press
	/// <summary>
	/// 获取当前被鼠标按下的控件
	/// </summary>
	public static GameObject GetPressedControl()
	{
		return UICamera.pressedObject;
	}
	
	/// <summary>
	/// 获取当前被鼠标按下的控件的名字
	/// </summary>
	public static string GetPressedControlName()
	{
		GameObject pressedObject = UICamera.pressedObject;
		if(pressedObject == null)
			return null;
		
		return pressedObject.name;
	}
	
	/// <summary>
	/// 检测控件是否为鼠标按下状态
	/// </summary>
	public static bool IsControlPressedState(string _controlName)
	{		
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return IsControlPressedState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为鼠标按下状态
	/// </summary>
	public static bool IsControlPressedState(string windowName, string controlName)
	{
		return IsControlPressedState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为鼠标按下状态
	/// </summary>
	public static bool IsControlPressedState(Window window, string controlName)
	{
		return IsControlPressedState(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为鼠标按下状态
	/// </summary>
	public static bool IsControlPressedState(GameObject control)
	{
		if(control == null)
			return false;
		
		return (control == GetPressedControl());
	}
	
	/// <summary>
	/// 设置控件为按下状态
	/// </summary>
	public static void SetControlPresseState(string _controlName, bool state)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlPresseState(GetControl(windowName, controlName), state);
	}
	
	/// <summary>
	/// 设置控件为按下状态
	/// </summary>
	public static void SetControlPresseState(string windowName, string controlName, bool state)
	{
		SetControlPresseState(GetControl(windowName, controlName), state);
	}
	
	/// <summary>
	/// 设置控件为按下状态
	/// </summary>
	public static void SetControlPresseState(Window window, string controlName, bool state)
	{
		SetControlPresseState(GetControl(window, controlName), state);
	}
	
	/// <summary>
	/// 设置控件为按下状态
	/// </summary>
	public static void SetControlPresseState(GameObject control, bool state)
	{
		if(control == null)
			return;
		
		if(state)
			UICamera.pressedObject = control;
		else if(UICamera.pressedObject == control)
			UICamera.pressedObject = null;
	}
	
	/// <summary>
	/// 获取Group中被鼠标按下对象的序号
	/// </summary>
	public static int GetGroupControlPressedIndex(string _controlName)
	{				
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

 		return GetGroupControlPressedIndex(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取Group中被鼠标按下对象的序号
	/// </summary>
	public static int GetGroupControlPressedIndex(string windowName, string controlName)
	{
		return GetGroupControlPressedIndex(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取Group中被鼠标按下对象的序号
	/// </summary>
	public static int GetGroupControlPressedIndex(Window window, string controlName)
	{
		return GetGroupControlPressedIndex(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取Group中被鼠标按下对象的序号
	/// </summary>
	public static int GetGroupControlPressedIndex(GameObject control)
	{
		if(control == null)
			return -1;
		
		GameObject pressedObject = GetPressedControl();
		if(pressedObject == null)
			return -1;
		
		UITable table = control.GetComponent<UITable>();
		if(table != null)
		{
			for(int i = 0; i < table.children.Count; i++)
			{
				if(NGUITools.IsChild(table.children[i], pressedObject.transform))
					return i;
			}
		}
		
		for(int i = 0; i < control.transform.childCount; i++)
		{
			if(pressedObject.transform.IsChildOf(control.transform.GetChild(i)))
				return i;
		}
		
		return -1;
	}
	
	/// <summary>
	/// 设置Group中被鼠标按下对象的序号
	/// </summary>
	public static void SetGroupControlPressedIndex(string _controlName, int index)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetGroupControlPressedIndex(GetControl(windowName, controlName), index);
	}
	
	/// <summary>
	/// 设置Group中被鼠标按下对象的序号
	/// </summary>
	public static void SetGroupControlPressedIndex(string windowName, string controlName, int index)
	{
		SetGroupControlPressedIndex(GetControl(windowName, controlName), index);
	}
	
	/// <summary>
	/// 设置Group中被鼠标按下对象的序号
	/// </summary>
	public static void SetGroupControlPressedIndex(Window window, string controlName, int index)
	{
		SetGroupControlPressedIndex(GetControl(window, controlName), index);
	}
	
	/// <summary>
	/// 设置Group中被鼠标按下对象的序号
	/// </summary>
	public static void SetGroupControlPressedIndex(GameObject control, int index)
	{
		if(control == null)
			return;
		
		Transform pressedObject = null;
		
		UITable table = control.GetComponent<UITable>();
		if(table != null)		
		{
			if(index >= 0 && index < table.children.Count)
				pressedObject = table.children[index];
		}
		else if(index >= 0 && index < control.transform.childCount)
			pressedObject = control.transform.GetChild(index);
		
		if(pressedObject != null)
			SetControlPresseState(pressedObject.gameObject, true);
	}

	#endregion //Control Press
	
    #region //Control Select
	/// <summary>
	/// 获取当前被鼠标选中的控件
	/// </summary>
	public static GameObject GetSelectedControl()
	{
		return UICamera.selectedObject;
	}
	
    /// <summary>
    /// 获取当前被鼠标选中的控件的对象
    /// </summary>
    public static string GetSelectedControlName()
    {
        GameObject selectedObject = UICamera.selectedObject;
		if(selectedObject == null)
			return null;
		
		return selectedObject.name;
    }
	
	/// <summary>
    /// 检测控件是否为被鼠标选中状态
    /// </summary>
    public static bool IsControlSelectedState(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return IsControlSelectedState(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 检测控件是否为被鼠标选中状态
    /// </summary>
    public static bool IsControlSelectedState(string windowName, string controlName)
    {
		return IsControlSelectedState(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 检测控件是否为被鼠标选中状态
    /// </summary>
    public static bool IsControlSelectedState(Window window, string controlName)
    {
		return IsControlSelectedState(GetControl(window, controlName));
    }

    /// <summary>
    /// 检测控件是否为被鼠标选中状态
    /// </summary>
    public static bool IsControlSelectedState(GameObject control)
    {
		if(control == null)
			return false;
		
		return (control == GetSelectedControl());
    }

    /// <summary>
    /// 设置控件的选中状态
    /// </summary>
    public static void SetControlSelectState(string _controlName, bool state)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlSelectState(GetControl(windowName, controlName), state);
    }
	
	/// <summary>
    /// 设置控件的选中状态
    /// </summary>
    public static void SetControlSelectState(string windowName, string controlName, bool state)
    {
		SetControlSelectState(GetControl(windowName, controlName), state);
    }
	
	/// <summary>
    /// 设置控件的选中状态
    /// </summary>
    public static void SetControlSelectState(Window window, string controlName, bool state)
    {
		SetControlSelectState(GetControl(window, controlName), state);
    }
	
	/// <summary>
    /// 设置控件的选中状态
    /// </summary>
    public static void SetControlSelectState(GameObject control, bool state)
    {
		if(control == null)
			return;

		UIImageButton umb = control.GetComponent<UIImageButton>();
		if(state)
		{
			UICamera.selectedObject = control;  
			
			if(umb != null)
			{
				if(umb.target != null)
					umb.target.spriteName = umb.hoverSprite;
				
				umb.GetComponent<BoxCollider>().enabled = false;
			}
		}
		else if(UICamera.selectedObject == control)
		{
			UICamera.selectedObject = null;
			if(umb != null)
			{
				if(umb.target != null)
					umb.target.spriteName = umb.normalSprite;
				
				umb.GetComponent<BoxCollider>().enabled = true;
			}
		}
    }
	
	/// <summary>
	/// 获取Group中被选中对象的序号
	/// </summary>
	public static int GetGroupControlSelectedIndex(string _controlName)
	{				
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

 		return GetGroupControlSelectedIndex(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取Group中被选中对象的序号
	/// </summary>
	public static int GetGroupControlSelectedIndex(string windowName, string controlName)
	{
		return GetGroupControlSelectedIndex(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取Group中被选中对象的序号
	/// </summary>
	public static int GetGroupControlSelectedIndex(Window window, string controlName)
	{
		return GetGroupControlSelectedIndex(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取Group中被选中对象的序号
	/// </summary>
	public static int GetGroupControlSelectedIndex(GameObject control)
	{
		if(control == null)
			return -1;
		
		GameObject selectedObject = GetSelectedControl();
		if(selectedObject == null)
			return -1;
		
		UITable table = control.GetComponent<UITable>();
		if(table != null)
		{
			for(int i = 0; i < table.children.Count; i++)
			{
				if(NGUITools.IsChild(table.children[i], selectedObject.transform))
					return i;
			}
		}
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
		{
			for(int i = 0; i < list.items.Count; i++)
			{
				if(list.selection == list.items[i])
					return i;
			}
		}
		
		for(int i = 0; i < control.transform.childCount; i++)
		{
			if(selectedObject.transform.IsChildOf(control.transform.GetChild(i)))
				return i;
		}
		
		return -1;
	}
	
	/// <summary>
	/// 设置Group中被选中对象的序号
	/// </summary>
	public static void SetGroupControlSelectedIndex(string _controlName, int index)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetGroupControlSelectedIndex(GetControl(windowName, controlName), index);
	}
	
	/// <summary>
	/// 设置Group中被选中对象的序号
	/// </summary>
	public static void SetGroupControlSelectedIndex(string windowName, string controlName, int index)
	{
		SetGroupControlSelectedIndex(GetControl(windowName, controlName), index);
	}
	
	/// <summary>
	/// 设置Group中被选中对象的序号
	/// </summary>
	public static void SetGroupControlSelectedIndex(Window window, string controlName, int index)
	{
		SetGroupControlSelectedIndex(GetControl(window, controlName), index);
	}
	
	/// <summary>
	/// 设置Group中被选中对象的序号
	/// </summary>
	public static void SetGroupControlSelectedIndex(GameObject control, int index)
	{
		if(control == null)
			return;
		
		Transform selectedObject = null;		
		UITable table = control.GetComponent<UITable>();
		if(table != null)
		{
			if(index >= 0 && index < table.children.Count)
				selectedObject = table.children[index];	
			
			if(selectedObject != null)
			{
				SetControlSelectState(selectedObject.gameObject, true);
				return;
			}
		}
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
		{
			if(index >= 0 && index < list.items.Count)
			{
				list.selection = list.items[index];
				return;
			}
		}

		if(index >= 0 && index < control.transform.childCount)
		{
			selectedObject = control.transform.GetChild(index);		
			if(selectedObject != null)
			{
				SetControlSelectState(selectedObject.gameObject, true);
				return;
			}			
		}
	}
	
	/// <summary>
	/// 设置下拉列表的选项内容
	/// </summary>
	public static void SetControlItemList(GameObject control, List<string> items)
	{
		if(control == null)
			return;
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list == null)
			return;
		
		list.items = items;
		if(items.Count > 0)
			list.selection = items[0];
	}
    #endregion  //Control Select
	
	#region //Control Checked
	/// <summary>
	/// 检测控件是否为被Checked状态
	/// </summary>
	public static bool IsControlCheckedState(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return IsControlCheckedState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为被Checked状态
	/// </summary>
	public static bool IsControlCheckedState(string windowName, string controlName)
	{
		return IsControlCheckedState(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为被Checked状态
	/// </summary>
	public static bool IsControlCheckedState(Window window, string controlName)
	{
		return IsControlCheckedState(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 检测控件是否为被Checked状态
	/// </summary>
	public static bool IsControlCheckedState(GameObject control)
	{
		if(control == null)
			return false;
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
			return checkbox.isChecked;
		
		return false;
	}
	
	/// <summary>
	/// 设置控件状态为被Checked状态
	/// </summary>>
	public static void SetControlCheckState(string _controlName, bool state)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlCheckState(GetControl(windowName, controlName), state);
	}	
	
	/// <summary>
	/// 设置控件状态为被Checked状态
	/// </summary>
	public static void SetControlCheckState(string windowName, string controlName, bool state)
	{
		SetControlCheckState(GetControl(windowName, controlName), state);
	}
	
	/// <summary>
	/// 设置控件状态为被Checked状态
	/// </summary>
	public static void SetControlCheckState(Window window, string controlName, bool state)
	{
		SetControlCheckState(GetControl(window, controlName), state);
	}
	
	/// <summary>
	/// 设置控件状态为被Checked状态
	/// </summary>
	public static void SetControlCheckState(GameObject control, bool state)
	{
		if(control == null)
			return;
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox == null)
			return;
		
		checkbox.isChecked = state;
	}
	#endregion //Control Checked
	
	#region //Control Visible
    /// <summary>
    /// 检测控件是否为可视状态
    /// </summary>
    public static bool IsControlVisible(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return IsControlVisible(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 检测控件是否为可视状态
    /// </summary>
    public static bool IsControlVisible(string windowName, string controlName)
    {
        return IsControlVisible(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 检测控件是否为可视状态
    /// </summary>
    public static bool IsControlVisible(Window window, string controlName)
    {
        return IsControlVisible(GetControl(window, controlName));
    }
	
	/// <summary>
    /// 检测控件是否为可视状态
    /// </summary>
    public static bool IsControlVisible(GameObject control)
    {
        if(control == null)
			return false;
		
        return control.gameObject.active;
    }

    /// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(string _controlName, bool Visible)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

       	SetControlVisible(GetControl(windowName, controlName), Visible, true);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(string _controlName, bool Visible, bool toChildren)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

       	SetControlVisible(GetControl(windowName, controlName), Visible, toChildren);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(string windowName, string controlName, bool Visible)
    {
        SetControlVisible(GetControl(windowName, controlName), Visible, true);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(string windowName, string controlName, bool Visible, bool toChildren)
    {
        SetControlVisible(GetControl(windowName, controlName), Visible, toChildren);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(Window window, string controlName, bool Visible)
    {
        SetControlVisible(GetControl(window, controlName), Visible, true);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(Window window, string controlName, bool Visible, bool toChildren)
    {
        SetControlVisible(GetControl(window, controlName), Visible, toChildren);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(GameObject control, bool Visible)
    {
        SetControlVisible(control, Visible, true);
    }
	
	/// <summary>
    /// 设置控件的可视状态
    /// </summary>
    public static void SetControlVisible(GameObject control, bool Visible, bool toChildren)
    {
        if(control == null)
			return;
		
		//隐藏前先刷新默认隐藏对象
//		UIDefaultHideChildren[] hides = control.GetComponentsInChildren<UIDefaultHideChildren>();
//		if(!Visible && toChildren)
//		{
//			foreach(UIDefaultHideChildren hide in hides)
//				hide.RefreshDefaultHideChildren();			
//		}
		
		if(toChildren)
			control.gameObject.SetActiveRecursively(Visible);
		else
			control.gameObject.active = Visible;
		
		//显示后隐藏默认隐藏对象
//		if(Visible && toChildren)
//		{			
//			foreach(UIDefaultHideChildren hide in hides)
//				hide.HideDefaultHideChildren();
//		}
    }
    #endregion  // Control Visible
	
	#region //Control Collider
	/// <summary>
	/// 设置控件的碰撞属性状态
	/// </summary>
	public static void SetControlColliderEnabled(string _controlName, bool enabled)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlColliderEnabled(GetControl(windowName, controlName), enabled);
	}
	
	/// <summary>
	/// 设置控件碰撞属性开关
	/// </summary>
	public static void SetControlColliderEnabled(string windowName, string controlName, bool enabled)
	{
		SetControlColliderEnabled(GetControl(windowName, controlName), enabled);
	}
	
	/// <summary>
	/// 设置控件碰撞属性开关
	/// </summary>
	public static void SetControlColliderEnabled(Window window, string controlName, bool enabled)
	{
		SetControlColliderEnabled(GetControl(window, controlName), enabled);
	}
	
	/// <summary>
	/// 设置控件碰撞属性开关
	/// </summary>
	public static void SetControlColliderEnabled(GameObject control, bool enabled)
	{
		if(control == null)
			return;
		
		BoxCollider collider = control.GetComponent<BoxCollider>();
		if(collider != null)
			collider.enabled = enabled;
	}
	#endregion //Control Collider
	
	#region //Control Text
    /// <summary>
    /// 获取控件Txt
    /// </summary>
    public static string GetControlText(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlText(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取控件Txt
    /// </summary>
    public static string GetControlText(string windowName, string controlName)
    {
		return GetControlText(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件Txt
    /// </summary>
    public static string GetControlText(Window window, string controlName)
    {
		return GetControlText(GetControl(window, controlName));
	}
	
	/// <summary>
    /// 获取控件Txt
    /// </summary>
    public static string GetControlText(GameObject control)
    {
		if(control == null)
			return null;
		
        UILabel label = control.GetComponent<UILabel>();
		if(label != null)
			return label.text;
		
		UIMix mix = control.GetComponent<UIMix>();
		if(mix != null)
			return mix.text;
		
		UIInput input = control.GetComponent<UIInput>();
		if(input != null)
			if(input.label != null)
				return label.text;
		
		UIButton button = control.GetComponent<UIButton>();
		if(button != null)
			if(button.label != null)
				return button.label.text;
		
		UIImageButton imageButton = control.GetComponent<UIImageButton>();
		if(imageButton != null)
			if(imageButton.label)
				return imageButton.label.text;
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
			if(checkbox.label != null)
				return checkbox.label.text;		
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
			if(list.textLabel != null)
				return list.textLabel.text;
		
		return null;
    }

    /// <summary>
    /// 设置控件Txt
    /// </summary>m>
    public static void SetControlText(string _controlName, string text)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        SetControlText(GetControl(windowName, controlName), text);
    }
	
	/// <summary>
    /// 设置控件Txt
    /// </summary>m>
    public static void SetControlText(string windowName, string controlName, string text)
    {
		SetControlText(GetControl(windowName, controlName), text);
	}
	
	/// <summary>
    /// 设置控件Txt
    /// </summary>m>
    public static void SetControlText(Window window, string controlName, string text)
    {
		SetControlText(GetControl(window, controlName), text);
	}
	
	/// <summary>
    /// 设置控件Txt
    /// </summary>m>
    public static void SetControlText(GameObject control, string text)
    {
		if( control == null )
			return;
		
		UILabel label = control.GetComponent<UILabel>();
		if(label != null)
		{
			label.text = text;
			return;
		}
		
		UIMix mix = control.GetComponent<UIMix>();
		if(mix != null)
		{
			mix.text = text;
			return;
		}
		
		UIInput input = control.GetComponent<UIInput>();
		if(input != null)
		{
			if(input.label != null)
			{
				label.text = text;
				return;
			}
		}
		
		UIButton button = control.GetComponent<UIButton>();
		if(button != null)
		{
			if(button.label != null)
			{
				button.label.text = text;				
				return;
			}
		}
		
		UIImageButton imageButton = control.GetComponent<UIImageButton>();
		if(imageButton != null)
		{
			if(imageButton.label)
			{
				imageButton.label.text = text;
				return;
			}
		}
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
		{
			if(checkbox.label != null)
			{
				checkbox.label.text = text;
				return;		
			}
		}
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
		{
			if(list.textLabel != null)
			{
				list.textLabel.text = text;
				return;
			}
		}
	}
    #endregion  //Control Text
	
	#region //Control LineWidth
	/// <summary>
    /// 获取控件字体行宽
    /// </summary>
    public static int GetControlLineWidth(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

		return GetControlLineWidth(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件字体行宽
    /// </summary>
    public static int GetControlLineWidth(string windowName, string controlName)
    {
		return GetControlLineWidth(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取控件字体行宽
    /// </summary>
    public static int GetControlLineWidth(Window window, string controlName)
    {
		return GetControlLineWidth(GetControl(window, controlName));
	}
	
	/// <summary>
    /// 获取控件字体行宽
    /// </summary>
    public static int GetControlLineWidth(GameObject control)
    {
		if(control == null)
			return 0;
		
		UILabel label = control.GetComponent<UILabel>();
        if (label != null)
            return label.lineWidth;
		
		UIMix mix = control.GetComponent<UIMix>();
		if(mix != null)
			return mix.lineWidth;
		
		return 0;
	}
	
	/// <summary>
    /// 设置控件字体行宽
    /// </summary>
    public static void SetControlLineWidth(string _controlName, int lineWidth)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

		SetControlLineWidth(GetControl(windowName, controlName), lineWidth);
	}
	
	/// <summary>
    /// 设置控件字体行宽
    /// </summary>
    public static void SetControlLineWidth(string windowName, string controlName, int lineWidth)
    {
		SetControlLineWidth(GetControl(windowName, controlName), lineWidth);
	}
	
	/// <summary>
    /// 设置控件字体行宽
    /// </summary>
    public static void SetControlLineWidth(Window window, string controlName, int lineWidth)
    {
		SetControlLineWidth(GetControl(window, controlName), lineWidth);
	}
	
	/// <summary>
    /// 设置控件字体行宽
    /// </summary>
    public static void SetControlLineWidth(GameObject control, int lineWidth)
    {
        if (control == null)
			return;
		
        UILabel label = control.GetComponent<UILabel>();
        if (label != null)
		{
            label.lineWidth = lineWidth;
			return;
		}
		
		UIMix mix = control.GetComponent<UIMix>();
		if(mix != null)
		{
			mix.lineWidth = lineWidth;
			return;
		}
    }
	#endregion //Control LineWidth
	
	#region //Control SliderValue
	/// <summary>
    /// 获取标准控件滑动进度值
    /// </summary>
    public static float GetControlSliderValue(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlSliderValue(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取标准控件滑动进度值
    /// </summary>
    public static float GetControlSliderValue(string windowName, string controlName)
    {
		return GetControlSliderValue(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取标准控件滑动进度值
    /// </summary>
    public static float GetControlSliderValue(Window window, string controlName)
    {
		return GetControlSliderValue(GetControl(window, controlName));
    }
	
	/// <summary>
    /// 获取标准控件滑动进度值
    /// </summary>
    public static float GetControlSliderValue(GameObject control)
    {
		if(control == null)
			return 0;

        UISlider slider = control.GetComponent<UISlider>();
        if (slider != null)
            return slider.sliderValue;

        return 0;
    }

    /// <summary>
    /// 设置标准控件滑动进度值
    /// </summary>
    public static void SetControlSliderValue(string _controlName, float sliderValue)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

       	SetControlSliderValue(GetControl(windowName, controlName), sliderValue);
    }
	
	/// <summary>
    /// 设置标准控件滑动进度值
    /// </summary>
    public static void SetControlSliderValue(string windowName, string controlName, float sliderValue)
    {
		SetControlSliderValue(GetControl(windowName, controlName), sliderValue);
    }
	
	/// <summary>
    /// 设置标准控件滑动进度值
    /// </summary>
    public static void SetControlSliderValue(Window window, string controlName, float sliderValue)
    {
		SetControlSliderValue(GetControl(window, controlName), sliderValue);
    }
	
	/// <summary>
    /// 设置标准控件滑动进度值
    /// </summary>
    public static void SetControlSliderValue(GameObject control, float sliderValue)
    {
		if(control == null)
			return;
		
        UISlider slider = control.GetComponent<UISlider>();
        if (slider != null)
            slider.sliderValue = sliderValue;
    }
	#endregion //Control SliderValue
	
	#region //Control ScrollValue
	/// <summary>
    /// 获取标准控件滚动进度值
    /// </summary>
    public static float GetControlScrollValue(string _controlName)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        return GetControlScrollValue(GetControl(windowName, controlName));
    }
	
	/// <summary>
    /// 获取标准控件滚动进度值
    /// </summary>
    public static float GetControlScrollValue(string windowName, string controlName)
    {
		return GetControlScrollValue(GetControl(windowName, controlName));
	}
	
	/// <summary>
    /// 获取标准控件滚动进度值
    /// </summary>
    public static float GetControlScrollValue(Window window, string controlName)
    {
		return GetControlScrollValue(GetControl(window, controlName));
	}
	
	/// <summary>
    /// 获取标准控件滚动进度值
    /// </summary>
    public static float GetControlScrollValue(GameObject control)
    {
		if(control == null)
			return 0;
		
		return GetControlScrollValue(control.GetComponent<UIScrollBar>());
	}
	
	/// <summary>
    /// 获取标准控件滚动进度值
    /// </summary>
    public static float GetControlScrollValue(UIScrollBar scroll)
    {
		if(scroll == null)
			return 0;
		
		return scroll.scrollValue;
	}
	
	/// <summary>
    /// 设置标准控件滚动进度值
    /// </summary>
    public static void SetControlScrollValue(string _controlName, float scrollValue)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlScrollValue(GetControl(windowName, controlName), scrollValue);
	}
	
	/// <summary>
    /// 设置标准控件滚动进度值
    /// </summary>
    public static void SetControlScrollValue(string windowName, string controlName, float scrollValue)
    {
		SetControlScrollValue(GetControl(windowName, controlName), scrollValue);
	}	
	
	/// <summary>
    /// 设置标准控件滚动进度值
    /// </summary>
    public static void SetControlScrollValue(Window window, string controlName, float scrollValue)
    {
		SetControlScrollValue(GetControl(window, controlName), scrollValue);
	}
	
	/// <summary>
    /// 设置标准控件滚动进度值
    /// </summary>
    public static void SetControlScrollValue(GameObject control, float scrollValue)
    {
		if(control == null)
			return;
		
		SetControlScrollValue(control.GetComponent<UIScrollBar>(), scrollValue);
	}
	
	/// <summary>
    /// 设置标准控件滚动进度值
    /// </summary>
    public static void SetControlScrollValue(UIScrollBar scroll, float scrollValue)
    {
		if(scroll == null)
			return;
		
		scroll.scrollValue = scrollValue;
	}
	#endregion //Control ScrollValue

    #endregion //Control Base

	
	
    #region //Standard Control

    #region //Control BackGround	
	/// <summary>
	/// 获取控件的背景
	/// </summary>
	public static GameObject GetControlBackGround(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlBackGround(GetControl(windowName, controlName));	
	}
	
	/// <summary>
	/// 获取控件的背景
	/// </summary>
	public static GameObject GetControlBackGround(string windowName, string controlName)
    {
		return GetControlBackGround(GetControl(windowName, controlName));	
	}
	
	/// <summary>
	/// 获取控件的背景
	/// </summary>
	public static GameObject GetControlBackGround(Window window, string controlName)
    {
		return GetControlBackGround(GetControl(window, controlName));	
	}
	
	/// <summary>
	/// 获取控件的背景
	/// </summary>
	public static GameObject GetControlBackGround(GameObject control)
    {
		if(control == null)
			return null;
		
		UIButton button = control.GetComponent<UIButton>();
		if(button != null)
			if(button.background != null)
				return button.background.gameObject;
		
		UIImageButton imageButton = control.GetComponent<UIImageButton>();
		if(imageButton != null)
			if(imageButton.target)
				return imageButton.target.gameObject;
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
			if(checkbox.backGround != null)
				return checkbox.backGround.gameObject;
		
		UISlider slider = control.GetComponent<UISlider>();
		if(slider != null)
			if(slider.backround != null)
				return slider.backround.gameObject;
		
		UIInput input = control.GetComponent<UIInput>();
		if(input != null)
			if(input.background != null)
				return input.background.gameObject;
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
			if(list.menuground != null)
				return list.menuground.gameObject;
		
		UIScrollBar scroll = control.GetComponent<UIScrollBar>();
		if(scroll != null)
			if(scroll.background != null)
				return scroll.background.gameObject;
		
		return null;
	}	
	
	/// <summary>
	/// 获取控件的背景图片名字
	/// </summary>
	public static string GetControlBackGroundName(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlBackGroundName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件的背景图片名字
	/// </summary>
	public static string GetControlBackGroundName(string windowName, string controlName)
    {
		return GetControlBackGroundName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件的背景图片名字
	/// </summary>
	public static string GetControlBackGroundName(Window window, string controlName)
    {
		return GetControlBackGroundName(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件的背景图片名字
	/// </summary>
	public static string GetControlBackGroundName(GameObject control)
    {
		GameObject controlBackground = GetControlBackGround(control);
		if(controlBackground == null)
			return null;
		
		return controlBackground.name;
	}
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(string _controlName, GameObject background)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlBackGround(GetControl(windowName, controlName), background);
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(string windowName, string controlName, GameObject background)
    {
		SetControlBackGround(GetControl(windowName, controlName), background);
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(Window window, string controlName, GameObject background)
    {
		SetControlBackGround(GetControl(window, controlName), background);
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(GameObject control, GameObject background)
    {
		if(control == null || background == null)
			return;
		
		SetControlBackGround(control, background.GetComponent<UISprite>());
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(string _controlName, UISprite bgSprite)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlBackGround(GetControl(windowName, controlName), bgSprite);
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(string windowName, string controlName, UISprite bgSprite)
    {
		SetControlBackGround(GetControl(windowName, controlName), bgSprite);
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(Window window, string controlName, UISprite bgSprite)
    {
		SetControlBackGround(GetControl(window, controlName), bgSprite);
    }
	
	/// <summary>
    /// 设置标准控件的背景图片
    /// </summary>
    public static void SetControlBackGround(GameObject control, UISprite bgSprite)
    {
		if(control == null || bgSprite == null)
			return;
        
		GameObject bgControl= GetControlBackGround(control);
		if(bgControl == null)
			return;		
		
		UIButton button = bgControl.GetComponent<UIButton>();
		if(button != null)
		{
			button.background = bgSprite;
			return;
		}
		
		UIImageButton imageButton = bgControl.GetComponent<UIImageButton>();
		if(imageButton != null)
		{
			imageButton.target = bgSprite;
			return;
		}
		
		UICheckbox checkbox = bgControl.GetComponent<UICheckbox>();
		if(checkbox != null)
		{
			checkbox.backGround = bgSprite;
			return;
		}
		
		UISlider slider = bgControl.GetComponent<UISlider>();
		if(slider != null)
		{
			slider.backround = bgSprite;
			return;
		}
		
		UIInput input = bgControl.GetComponent<UIInput>();
		if(input != null)
		{
			input.background = bgSprite;
			return;
		}
		
		UIPopupList list = bgControl.GetComponent<UIPopupList>();
		if(list != null)
		{
			list.menuground = bgSprite;
			return;
		}
		
		UIScrollBar scroll = bgControl.GetComponent<UIScrollBar>();
		if(scroll != null)
		{
			scroll.background = bgSprite;
			return;
		}
    }
    #endregion //Control BackGround

    #region //Control Foreground
	/// <summary>
	/// 获取控件前景控件
	/// </summary>
	public static GameObject GetControlForeground(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlForeground(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件前景控件
	/// </summary>
	public static GameObject GetControlForeground(string windowName, string controlName)
    {
		return GetControlForeground(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件前景控件
	/// </summary>
	public static GameObject GetControlForeground(Window window, string controlName)
    {
		return GetControlForeground(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件前景控件
	/// </summary>
	public static GameObject GetControlForeground(GameObject control)
    {
		if(control == null)
			return null;
		
		UISlider slider = control.GetComponent<UISlider>();
		if(slider != null)
			if(slider.foreground != null)
				return slider.foreground.gameObject;
		
		return null;
	}
	
	/// <summary>
	/// 获取控件前景控件名字
	/// </summary>
	public static string GetControlForegroundName(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlForegroundName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件前景控件名字
	/// </summary>
	public static string GetControlForegroundName(string windowName, string controlName)
    {
		return GetControlForegroundName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件前景控件名字
	/// </summary>
	public static string GetControlForegroundName(Window window, string controlName)
    {
		return GetControlForegroundName(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件前景控件名字
	/// </summary>
	public static string GetControlForegroundName(GameObject control)
    {
		GameObject fgControl = GetControlForeground(control);
		if(fgControl == null)
			return null;
		
		return fgControl.name;
	}
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(string _controlName, GameObject foreground)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlForeground(GetControl(windowName, controlName), foreground);
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(string windowName, string controlName, GameObject foreground)
    {
		SetControlForeground(GetControl(windowName, controlName), foreground);
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(Window window, string controlName, GameObject foreground)
    {
		SetControlForeground(GetControl(window, controlName), foreground);
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(GameObject control, GameObject foreground)
    {
		if(control == null || foreground == null)
			return;
        
		SetControlForeground(control, foreground.GetComponent<UISprite>());
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(string _controlName, UISprite fgSprite)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlForeground(GetControl(windowName, controlName), fgSprite);
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(string windowName, string controlName, UISprite fgSprite)
    {
		SetControlForeground(GetControl(windowName, controlName), fgSprite);
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(Window window, string controlName, UISprite fgSprite)
    {
		SetControlForeground(GetControl(window, controlName), fgSprite);
    }
	
	/// <summary>
    /// 设置标准控件的前景图片
    /// </summary>
    public static void SetControlForeground(GameObject control, UISprite fgSprite)
    {
		if(control == null || fgSprite == null)
			return;
        
		GameObject fgControl= GetControlForeground(control);
		if(fgControl == null)
			return;		

		UISlider slider = fgControl.GetComponent<UISlider>();
		if(slider != null)
		{
			slider.foreground = fgSprite;
			return;
		}
    }
    #endregion //Control Foreground

    #region //Control Checkmark
	/// <summary>
	/// 获取标准控件的选中Mark控件
	/// </summary>
	public static GameObject GetControlCheckmark(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlCheckmark(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件
	/// </summary>
	public static GameObject GetControlCheckmark(string windowName, string controlName)
    {
		return GetControlCheckmark(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件
	/// </summary>
	public static GameObject GetControlCheckmark(Window window, string controlName)
    {
		return GetControlCheckmark(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件
	/// </summary>
	public static GameObject GetControlCheckmark(GameObject control)
    {
		if(control == null)
			return null;
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
			if(checkbox.checkSprite != null)
				return checkbox.checkSprite.gameObject;
		
		return null;
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件名字
	/// </summary>
	public static string GetControlCheckmarkName(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlCheckmarkName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件名字
	/// </summary>
	public static string GetControlCheckmarkName(string windowName, string controlName)
    {
		return GetControlCheckmarkName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件名字
	/// </summary>
	public static string GetControlCheckmarkName(Window window, string controlName)
    {		
		return GetControlCheckmarkName(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取标准控件的选中Mark控件名字
	/// </summary>
	public static string GetControlCheckmarkName(GameObject control)
    {
		GameObject cmControl = GetControlCheckmark(control);
		if(cmControl == null)
			return null;
		
		return cmControl.name;
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(string _controlName, GameObject checkmark)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlCheckmark(GetControl(windowName, controlName), checkmark);
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(string windowName, string controlName, GameObject checkmark)
    {
		SetControlCheckmark(GetControl(windowName, controlName), checkmark);
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(Window window, string controlName, GameObject checkmark)
    {
		SetControlCheckmark(GetControl(window, controlName), checkmark);
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(GameObject control, GameObject checkmark)
    {
		if(control == null || checkmark == null)
			return;
		
		SetControlCheckmark(control, checkmark.GetComponent<UISprite>());
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(string _controlName, UISprite cmSprite)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlCheckmark(GetControl(windowName, controlName), cmSprite);
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(string windowName, string controlName, UISprite cmSprite)
    {
		SetControlCheckmark(GetControl(windowName, controlName), cmSprite);
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(Window window, string controlName, UISprite cmSprite)
    {
		SetControlCheckmark(GetControl(window, controlName), cmSprite);
	}
	
	/// <summary>
	/// 设置标准控件的选中Mark控件资源
	/// </summary>
	public static void SetControlCheckmark(GameObject control, UISprite cmSprite)
    {
		if(control == null || cmSprite == null)
			return;
		
		GameObject cmControl = GetControlCheckmark(control);
		if(control == null)
			return;
		
		UICheckbox checkbox = cmControl.GetComponent<UICheckbox>();
		if(checkbox != null)
		{
			checkbox.checkSprite = cmSprite;
			return;
		}
	}
    #endregion //Control Checkmark

    #region //Control Thumb
	/// <summary>
	/// 获取控件游标
	/// </summary>
	public static GameObject GetControlThumb(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlThumb(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件游标
	/// </summary>
	public static GameObject GetControlThumb(string windowName, string controlName)
    {
		return GetControlThumb(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件游标
	/// </summary>
	public static GameObject GetControlThumb(Window window, string controlName)
    {
		return GetControlThumb(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件游标
	/// </summary>
	public static GameObject GetControlThumb(GameObject control)
    {
		if(control == null)
			return null;
		
		UISlider slider = control.GetComponent<UISlider>();
		if(slider != null)
			if(slider.thumb != null)
				return slider.thumb.gameObject;
		
		return null;
	}
	
	/// <summary>
	/// 获取控件游标名字
	/// </summary>
	public static string GetControlThumbName(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlThumbName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件游标名字
	/// </summary>
	public static string GetControlThumbName(string windowName, string controlName)
    {
		return GetControlThumbName(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取控件游标名字
	/// </summary>
	public static string GetControlThumbName(Window window, string controlName)
    {
		return GetControlThumbName(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取控件游标名字
	/// </summary>
	public static string GetControlThumbName(GameObject control)
    {
		GameObject tbControl = GetControlThumb(control);
		if(tbControl == null)
			return null;
		
		return tbControl.name;
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(string _controlName, GameObject thumb)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlThumb(GetControl(windowName, controlName), thumb);
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(string windowName, string controlName, GameObject thumb)
    {
		SetControlThumb(GetControl(windowName, controlName), thumb);
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(Window window, string controlName, GameObject thumb)
    {
		SetControlThumb(GetControl(window, controlName), thumb);
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(GameObject control, GameObject thumb)
    {
		if(control == null || thumb == null)
			return;
		
		SetControlThumb(GetControlThumb(control), thumb);
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(string _controlName, UISprite tbSprite)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlThumb(GetControl(windowName, controlName), tbSprite);
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(string windowName, string controlName, UISprite tbSprite)
    {
		SetControlThumb(GetControl(windowName, controlName), tbSprite);
	}
	
	/// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(Window window, string controlName, UISprite tbSprite)
    {
		SetControlThumb(GetControl(window, controlName), tbSprite);
	}
	
    /// <summary>
	/// 设置控件游标
	/// </summary>
	public static void SetControlThumb(GameObject control, UISprite tbSprite)
    {
		if(control == null || tbSprite == null)
			return;
		
		GameObject tbControl = GetControlThumb(control);
		if(tbControl == null)		
			return;
		
		UISlider slider = tbControl.GetComponent<UISlider>();
		if(slider != null)
		{
			slider.thumb = tbSprite;
			return;
		}
	}
    #endregion //Control Thumb

    #region //Control Label
	/// <summary>
	/// 获取控件的Lable控件
	/// </summary>
	public static GameObject GetControlLabel(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlLabel(GetControl(windowName, controlName));
    }
	
	/// <summary>
	/// 获取控件的Lable控件
	/// </summary>
	public static GameObject GetControlLabel(string windowName, string controlName)
    {
       return GetControlLabel(GetControl(windowName, controlName));
    }
	
	/// <summary>
	/// 获取控件的Lable控件
	/// </summary>
	public static GameObject GetControlLabel(Window window, string controlName)
    {
       return GetControlLabel(GetControl(window, controlName));
    }
	
	/// <summary>
	/// 获取控件的Lable控件
	/// </summary>
	public static GameObject GetControlLabel(GameObject control)
    {
        if(control == null)
			return null;
		
		UIButton button = control.GetComponent<UIButton>();
		if(button != null)
			if(button.label != null)
				return button.label.gameObject;
		
		UIImageButton imageButton = control.GetComponent<UIImageButton>();
		if(imageButton != null)
			if(imageButton.label)
				return imageButton.label.gameObject;
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
			if(checkbox.label != null)
				return checkbox.label.gameObject;
		
		UIInput input = control.GetComponent<UIInput>();
		if(input != null)
			if(input.label != null)
				return input.label.gameObject;
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
			if(list.textLabel != null)
				return list.textLabel.gameObject;
	
		return null;
    }
	
	/// <summary>
	/// 获取控件的Lable控件名字
	/// </summary>
	public static string GetControlLabelName(string _controlName)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetControlLabelName(GetControl(windowName, controlName));
    }
	
	/// <summary>
	/// 获取控件的Lable控件名字
	/// </summary>
	public static string GetControlLabelName(string windowName, string controlName)
    {
		return GetControlLabelName(GetControl(windowName, controlName));
    }
	
	/// <summary>
	/// 获取控件的Lable控件名字
	/// </summary>
	public static string GetControlLabelName(Window window, string controlName)
    {
		return GetControlLabelName(GetControl(window, controlName));
    }
	
	/// <summary>
	/// 获取控件的Lable控件名字
	/// </summary>
	public static string GetControlLabelName(GameObject control)
    {
        GameObject lbControl = GetControlLabel(control);
		if(lbControl == null)
			return null;
		
		return lbControl.name;
    }
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(string _controlName, GameObject lable)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlLabel(GetControl(windowName, controlName), lable);
	}
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(string windowName, string controlName, GameObject lable)
    {
		SetControlLabel(GetControl(windowName, controlName), lable);
	}
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(Window window, string controlName, GameObject lable)
    {
		SetControlLabel(GetControl(window, controlName), lable);
	}	
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(GameObject control, GameObject lable)
    {
		if(control == null || lable == null)
			return;
		
		SetControlLabel(control, lable.GetComponent<UILabel>());
	}
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(string _controlName, UILabel lable)
    {
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		SetControlLabel(GetControl(windowName, controlName), lable);
	}
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(string windowName, string controlName, UILabel lable)
    {
		SetControlLabel(GetControl(windowName, controlName), lable);
	}
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(Window window, string controlName, UILabel lable)
    {
		SetControlLabel(GetControl(window, controlName), lable);
	}
	
	/// <summary>
	/// 设置控件的Lable控件
	/// </summary>
	public static void SetControlLabel(GameObject control, UILabel lable)
    {
		if(control == null || lable == null)
			return;
		
		GameObject lbControl = GetControlLabel(control);
		if(lbControl == null)
			return;
		
		UIButton button = control.GetComponent<UIButton>();
		if(button != null)
		{
			button.label = lable;
			return;
		}
		
		UIImageButton imageButton = control.GetComponent<UIImageButton>();
		if(imageButton != null)
		{
			imageButton.label = lable;
			return;
		}
		
		UICheckbox checkbox = control.GetComponent<UICheckbox>();
		if(checkbox != null)
		{
			checkbox.label = lable;
			return;
		}
		
		UIInput input = control.GetComponent<UIInput>();
		if(input != null)
		{
			input.label = lable;
			return;
		}
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
		{
			list.textLabel = lable;
			return;
		}
    }
    #endregion  //Control Label

    #region //Control Slider
    /// <summary>
    /// 设置标准控件滑动进度值
    /// </summary>
    public static void SetControlSliderFullWidth(string _controlName, float width)
    {
        string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
            UISlider slider = controlObj.GetComponent<UISlider>();
            if (slider != null)
                slider.fullSize = new Vector2(width, slider.fullSize.y);
        }
    }
    #endregion //Control Slider

    #region //Control Group
	/// <summary>
	/// 获取Group控件元素个数
	/// </summary>
	public static int GetGroupControlItemCount(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		return GetGroupControlItemCount(GetControl(windowName, controlName));
	}	
	
	/// <summary>
	/// 获取Group控件元素个数
	/// </summary>
	public static int GetGroupControlItemCount(string windowName, string controlName)
	{
		return GetGroupControlItemCount(GetControl(windowName, controlName));
	}
	
	/// <summary>
	/// 获取Group控件元素个数
	/// </summary>
	public static int GetGroupControlItemCount(Window window, string controlName)
	{
		return GetGroupControlItemCount(GetControl(window, controlName));
	}
	
	/// <summary>
	/// 获取Group控件元素个数
	/// </summary>
	public static int GetGroupControlItemCount(GameObject control)
	{
		if(control == null)
			return 0;
		
		UITable table = control.GetComponent<UITable>();
        if (table != null)
            return table.children.Count;
		
		UICheckboxGroup cbGroup = control.GetComponent<UICheckboxGroup>();
		if(cbGroup != null)
			return cbGroup.childeren.Count;
		
		UIPopupList list = control.GetComponent<UIPopupList>();
		if(list != null)
			return list.items.Count;
		
		return 0;
	}
	
    /// <summary>
    /// 向Table控件添加一个元素
    /// </summary>
    public static GameObject AddItemToTable(string newItemName, string tableControl)
    {
        return AddItemToTable(newItemName, tableControl, -1);
    }
	
	/// <summary>
    /// 向Table控件添加一个元素
    /// </summary>
    public static GameObject AddItemToTable(string newItemName, GameObject tableControl)
    {
      	return AddItemToTable(newItemName, tableControl, -1);
    }

    /// <summary>
    /// 向Table控件添加一个元素,并指定序号
    /// </summary>
    public static GameObject AddItemToTable(string newItemName, string tableControl, int index)
    {
        string windowName = tableControl.Split('_')[0];
        string controlName = tableControl.Substring(windowName.Length + 1);

       	return AddItemToTable(newItemName, GetControl(windowName, controlName), index);
    }
	
	/// <summary>
    /// 向Table控件添加一个元素,并指定序号
    /// </summary>
	public static GameObject AddItemToTable(string newItemName, GameObject tableControl, int index)
    {
		if (tableControl == null)
        	return null;
	
        UITable table = tableControl.GetComponent<UITable>();
        if (table != null)
			return AddItemToTable(newItemName, table, index);
		
		return null;
	}
	
	/// <summary>
    /// 向Grid控件添加一个元素,并指定序号
    /// </summary>
	public static GameObject AddItemToGrid(string newItemName, GameObject gridControl, int index)
    {
		if (gridControl == null)
        	return null;
		
		UIGrid grid = gridControl.GetComponent<UIGrid>();
		if(grid != null)
			return AddItemToGrid(newItemName, grid, index);
		
		return null;
	}
	
	/// <summary>
    /// 向Table控件添加一个元素,并指定序号
    /// </summary>
	public static GameObject AddItemToTable(string newItemName, UITable table)
	{
		return AddItemToTable(newItemName, table, -1);
	}
	
	/// <summary>
    /// 向Grid控件添加一个元素,并指定序号
    /// </summary>
	public static GameObject AddItemToGrid(string newItemName, UIGrid grid)
	{
		return AddItemToGrid(newItemName, grid, -1);
	}
	
	/// <summary>
    /// 向Table控件添加一个元素,并指定序号
    /// </summary>
	public static GameObject AddItemToTable(string newItemName, UITable table, int index)
	{
        if (table == null)
            return null;
		
		if(table.itemTemplate == null)
			return null;
		
//        Transform newItem = table.transform.FindChild(newItemName);
//        if (newItem != null)
//            return null;
		
		Transform itemTrans = table.itemTemplate.transform;
        GameObject newItemObj = Instantiate(table.itemTemplate) as GameObject;
		newItemObj.SetActiveRecursively(true);
		newItemObj.name = (string.IsNullOrEmpty(newItemName) ? table.itemTemplate.name : newItemName);
		
		Transform newItem = newItemObj.transform;       
        newItem.parent = table.transform;
        newItem.localPosition = itemTrans.localPosition;
        newItem.localRotation = itemTrans.localRotation;
        newItem.localScale = itemTrans.localScale;
		
		if(index == -1)
			index = table.children.Count;

		if(index >= 0 && index <= table.children.Count)
		{
			table.children.Insert(index, newItem);
			table.Reposition(false);
			
			return newItem.gameObject;
		}
		else
		{
			DestroyImmediate(newItemObj);
		}
		
		return null;
	}
	
	/// <summary>
    /// 向Grid控件添加一个元素,并指定序号
    /// </summary>
	public static GameObject AddItemToGrid(string newItemName, UIGrid grid, int index)
	{
        if (grid == null)
            return null;
		
		if(grid.itemTemplate == null)
			return null;
		
        Transform newItem = grid.transform.FindChild(newItemName);
        if (newItem != null)
            return null;
		
		Transform itemTrans = grid.itemTemplate.transform;
        GameObject newItemObj = Instantiate(grid.itemTemplate) as GameObject;
		newItemObj.SetActiveRecursively(true);
		newItemObj.name = newItemName;
		
		newItem = newItemObj.transform;       
        newItem.parent = grid.transform;
        newItem.localPosition = itemTrans.localPosition;
        newItem.localRotation = itemTrans.localRotation;
        newItem.localScale = itemTrans.localScale;
		
		if(index == -1)
			index = grid.children.Count;

		if(index >= 0 && index <= grid.children.Count)
		{
			grid.children.Insert(index, newItem);
			grid.Reposition();
			
			return newItem.gameObject;
		}
		else
		{
			DestroyImmediate(newItemObj);
		}
		
		return null;
	}
	
	/// <summary>
	/// Removes the item at form table.
	/// </summary>
	/// </param>
	public static void RemoveItemAtFromTable(string tableControl, int index)
	{
		string windowName = tableControl.Split('_')[0];
        string controlName = tableControl.Substring(windowName.Length + 1);
		
		RemoveItemAtFromTable(GetControl(windowName, controlName), index);		
	}
	
	//删除Table表中指定的元素
	public static void RemoveItemAtFromTable(GameObject control, int index)
	{
		UITable table = control.GetComponent<UITable>();
        if (table == null)
            return;
		
		if(index >= 0 && index < table.children.Count)
		{
			DestroyImmediate(table.children[index]);
			table.children.RemoveAt(index);
			table.Reposition(false);
		}
	}
	
	public static void RemoveItemAtFromTable( GameObject control, string name )
	{
		UITable table = control.GetComponent<UITable>();
        if (table == null)
            return;
		if( name == "" )
			return;
		table.DestroyChild( name );
	}
	
	/// <summary>
	/// Gets the index of the table group hovered.
	/// </summary>
	/// <returns>
	public static int GetTableGroupHoveredIndex(string _controlName)
	{
		GameObject hoveredObject = UICamera.currentTouch.current;
		if(hoveredObject == null)
			return -1;
		
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
			UITable table = controlObj.GetComponent<UITable>();
			if(table != null)
			{
				for(int i = 0; i < table.children.Count; i++)
				{
					if(NGUITools.IsChild(table.children[i], controlObj.transform))
						return i;
				}
			}
			
			for(int i = 0; i < controlObj.transform.childCount; i++)
			{
				if(hoveredObject.transform.IsChildOf(controlObj.transform.GetChild(i)))
					return i;
			}
		}
		
		return -1;
	}
	
	/// <summary>
	/// Gets the index of the table group selected.
	/// </summary>
	public static int GetTableGroupSelectedIndex(string _controlName)
	{
		GameObject selectedObject = UICamera.selectedObject;
		if(selectedObject == null)
			return -1;
		
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);

        GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
			UITable table = controlObj.GetComponent<UITable>();
			if(table != null)
			{
				for(int i = 0; i < table.children.Count; i++)
				{
					if(NGUITools.IsChild(table.children[i], controlObj.transform))
						return i;
				}
			}
			
			for(int i = 0; i < controlObj.transform.childCount; i++)
			{
				if(selectedObject.transform.IsChildOf(controlObj.transform.GetChild(i)))
					return i;
			}
		}
		
		return -1;
	}
	
	/// <summary>
	/// Sets the index of the tale group selected.
	/// </summary>
	public static void SetTaleGroupSelectedIndex(string _controlName, int index)
	{
		if(index < 0)
			return;
		
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
			UITable tabel = controlObj.GetComponent<UITable>();
			if(tabel != null)
			{
				if(index < tabel.children.Count)
				{					
					Transform child = tabel.children[index];
					if(child != null)
					{
						UICamera.selectedObject = child.gameObject;					
						
						UIImageButton button = child.GetComponent<UIImageButton>();
						if(button != null)
						{
							if(button.target != null)
								button.target.spriteName = button.pressedSprite;
						}
						else
						{
							UICheckbox checkbox = child.GetComponent<UICheckbox>();
							if(checkbox != null)
								checkbox.isChecked = true;
						}
					}
				}
			}
		}
	}
    #endregion  //Control Group
	
	#region //Control RadioGroup
	/// <summary>
	/// Gets the index of the radio group state by.
	/// </summary>
	public static bool GetRadioGroupCheckedStateByIndex(string _controlName, int index)
	{
		if(index < 0)
			return false;
		
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
			UICheckboxGroup checkboxGroup = controlObj.GetComponent<UICheckboxGroup>();
			if(checkboxGroup != null)
			{
				if(index >= checkboxGroup.childeren.Count)
					return false;
				
				UICheckbox checkbox = checkboxGroup.childeren[index];
				if(checkbox != null)
					return checkbox.isChecked;
			}
		}
		
		return false;
	}
	
	/// <summary>
	/// Sets the index of the radio group checked.
	/// </summary>
	public static void SetRadioGroupCheckedIndex(string _controlName, int index)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
			UICheckboxGroup checkboxGroup = controlObj.GetComponent<UICheckboxGroup>();
			if(checkboxGroup != null)
				checkboxGroup.SetCheckedIndex(index);
		}
	}
	
	/// <summary>
	/// Gets the index of the radio group checked.
	/// </summary>
	public static int GetRadioGroupCheckedIndex(string _controlName)
	{
		string windowName = _controlName.Split('_')[0];
        string controlName = _controlName.Substring(windowName.Length + 1);
		
		GameObject controlObj = GetControl(windowName, controlName);
        if (controlObj != null)
        {
			UICheckboxGroup checkboxGroup = controlObj.GetComponent<UICheckboxGroup>();
			if(checkboxGroup != null)
				return checkboxGroup.checkedIndex;
		}
		
		return -1;
	}
	#endregion //Control RadioGroup

    #endregion //Standard Control



//    #region //Create UI
//
//    #region //Panel & Window
//    public static UIPanel CreatPanel(GameObject parent, string name)
//    {
//        UIPanel panel = NGUITools.AddChild<UIPanel>(parent);
//        panel.name = name;
//
//        return panel;
//    }
//
//    public static Window CreatWindow(GameObject parent, string name)
//    {
//        Window window = GetWindow(name);
//        if(window != null)
//            return window;
//
//        UIPanel panel = CreatPanel(parent, name);
//		window = panel.gameObject.AddComponent<Window>();
//        windows.Add(name, window);
//
//        return window;
//    }
//    #endregion //Panel & Window
//
//    #region //Label
//    public static UILabel CreateLabel(GameObject parent, string name)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        UILabel label = NGUITools.AddWidget<UILabel>(parent);
//        label.name = name;
//        label.depth = depth;
//
//        label.font = defaultFont;
//        label.MakePixelPerfect();
//
//        return label;
//    }
//    #endregion //Label
//
//    #region //Sprite
//    public static T CreateSprite<T>(GameObject parent, string name) where T : UISprite
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        T sprite = NGUITools.AddChild<T>(parent);
//        sprite.name = name;
//        sprite.depth = depth;
//
//        sprite.atlas = defaultAtlas;
//        SetDefualtScale(sprite);
//
//        return sprite;
//    }
//
//    public static UISprite CreateSprite(GameObject parent, string name)
//    {
//        return CreateSprite<UISprite>(parent, name);
//    }
//
//    public static UISlicedSprite CreateSlicedSprite(GameObject parent, string name)
//    {
//        return CreateSprite<UISlicedSprite>(parent, name);
//    }
//
//    public static UITiledSprite CreateTiledSprite(GameObject parent, string name)
//    {
//        return CreateSprite<UITiledSprite>(parent, name);
//    }
//
//    public static UIFilledSprite CreateFilledSprite(GameObject parent, string name)
//    {
//        return CreateSprite<UIFilledSprite>(parent, name);
//    }
//    #endregion //Sprite
//
//    #region //Button
//    public static UIButton CreateButton(GameObject parent, string name)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        GameObject go = NGUITools.AddChild(parent);
//        go.name = name;
//
//        UISlicedSprite bg = NGUITools.AddWidget<UISlicedSprite>(go);
//        bg.name = "Background";
//        bg.depth = depth;
//        bg.atlas = defaultAtlas;
//        bg.transform.localScale = new Vector3(150f, 40f, 1f);
//        bg.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(bg);
//
//        UILabel lbl = NGUITools.AddWidget<UILabel>(go);
//        lbl.font = defaultFont;
//        lbl.text = go.name;
//        lbl.MakePixelPerfect();
//
//        // Add a collider
//        NGUITools.AddWidgetCollider(go);
//
//        // Add the scripts
//        go.AddComponent<UIButton>().tweenTarget = bg.gameObject;
//        go.AddComponent<UIButtonScale>();
//        go.AddComponent<UIButtonOffset>();
//        go.AddComponent<UIButtonSound>();
//
//        return go.GetComponent<UIButton>();
//    }
//
//    public static UIImageButton CreateImageButton(GameObject parent, string name)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        GameObject go = NGUITools.AddChild(parent);
//        go.name = name;
//
//        UISlicedSprite sprite = NGUITools.AddWidget<UISlicedSprite>(go);
//
//        sprite.name = "Background";
//        sprite.depth = depth;
//        sprite.atlas = defaultAtlas;
//        sprite.transform.localScale = new Vector3(150f, 40f, 1f);
//        sprite.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(sprite);
//
//        // Add a collider
//        NGUITools.AddWidgetCollider(go);
//
//        // Add the scripts
//        UIImageButton ib = go.AddComponent<UIImageButton>();
//        ib.target = sprite;
//        go.AddComponent<UIButtonSound>();
//
//        return ib;
//    }
//    #endregion //Button
//
//    #region //CheckBox
//    public static UICheckbox CreateCheckbox(GameObject parent, string name)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        GameObject go = NGUITools.AddChild(parent);
//        go.name = "Checkbox";
//
//        UISlicedSprite bg = NGUITools.AddWidget<UISlicedSprite>(go);
//        bg.name = "Background";
//        bg.depth = depth;
//        bg.atlas = defaultAtlas;
//        bg.transform.localScale = new Vector3(26f, 26f, 1f);
//        bg.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(bg);
//
//        UISprite fg = NGUITools.AddWidget<UISprite>(go);
//        fg.name = "Checkmark";
//        fg.atlas = defaultAtlas;
//        fg.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(fg);
//
//        UILabel lbl = NGUITools.AddWidget<UILabel>(go);
//        lbl.font = defaultFont;
//        lbl.text = go.name;
//        lbl.pivot = UIWidget.Pivot.Left;
//        lbl.transform.localPosition = new Vector3(16f, 0f, 0f);
//        lbl.MakePixelPerfect();
//
//        // Add a collider
//        NGUITools.AddWidgetCollider(go);
//
//        // Add the scripts
//        go.AddComponent<UICheckbox>().checkSprite = fg;
//        go.AddComponent<UIButton>().tweenTarget = bg.gameObject;
//        go.AddComponent<UIButtonScale>().tweenTarget = bg.transform;
//        go.AddComponent<UIButtonSound>();
//
//        return  go.AddComponent<UICheckbox>();
//    }
//    #endregion //CheckBox
//
//    #region //Slider
//    public static UISlider CreateSlider(GameObject parent, string name)
//    {
//        return CreateBaseSlider(parent, name, true);
//    }
//
//    public static UISlider CreateProgressBar(GameObject parent, string name)
//    {
//        return CreateBaseSlider(parent, name, false);
//    }
//
//    static UISlider CreateBaseSlider(GameObject parent, string name, bool slider)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        GameObject go = NGUITools.AddChild(parent);
//        go.name = name;
//
//        // Background sprite
//        UISprite back = NGUITools.AddWidget<UISlicedSprite>(go);
//
//        back.name = "Background";
//        back.depth = depth;
//        back.pivot = UIWidget.Pivot.Left;
//        back.atlas = defaultAtlas;
//        back.transform.localScale = new Vector3(200f, 30f, 1f);
//        back.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(back);
//
//        // Fireground sprite
//        UISprite front = NGUITools.AddWidget<UISlicedSprite>(go);
//
//        front.name = "Foreground";
//        front.pivot = UIWidget.Pivot.Left;
//        front.atlas = defaultAtlas;
//        front.transform.localScale = new Vector3(200f, 30f, 1f);
//        front.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(front);
//
//        // Add a collider
//        if (slider) NGUITools.AddWidgetCollider(go);
//
//        // Add the slider script
//        UISlider uiSlider = go.AddComponent<UISlider>();
//        uiSlider.foreground = front.transform;
//        uiSlider.fullSize = front.transform.localScale;
//
//        // Thumb sprite
//        if (slider)
//        {
//            UISprite thb = NGUITools.AddWidget<UISlicedSprite>(go);
//
//            thb.name = "Thumb";
//            thb.atlas = defaultAtlas;
//            thb.transform.localPosition = new Vector3(200f, 0f, 0f);
//            thb.transform.localScale = new Vector3(20f, 40f, 1f);
//            thb.MakePixelPerfect();
//            //sclae to the defualt
//            SetDefualtScale(thb);
//
//            NGUITools.AddWidgetCollider(thb.gameObject);
//            thb.gameObject.AddComponent<UIButtonColor>();
//            thb.gameObject.AddComponent<UIButtonScale>();
//
//            uiSlider.thumb = thb.transform;
//        }
//        uiSlider.sliderValue = 0.75f;
//
//        return go.GetComponent<UISlider>();
//    }
//    #endregion //Slider
//
//    #region //Input
//    public static UIInput CreateInput(GameObject parent, string name)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        GameObject go = NGUITools.AddChild(parent);
//        go.name = name;
//
//        float padding = 3f;
//
//        UISlicedSprite bg = NGUITools.AddWidget<UISlicedSprite>(go);
//        bg.name = "Background";
//        bg.depth = depth;
//        bg.atlas = defaultAtlas;
//        bg.pivot = UIWidget.Pivot.Left;
//        bg.transform.localScale = new Vector3(400f, defaultFont.size + padding * 2f, 1f);
//        bg.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(bg);
//
//        UILabel lbl = NGUITools.AddWidget<UILabel>(go);
//        lbl.font = defaultFont;
//        lbl.pivot = UIWidget.Pivot.Left;
//        lbl.transform.localPosition = new Vector3(padding, 0f, 0f);
//        lbl.multiLine = false;
//        lbl.supportEncoding = false;
//        lbl.lineWidth = Mathf.RoundToInt(400f - padding * 2f);
//        lbl.text = "You can type here";
//        lbl.MakePixelPerfect();
//
//        // Add a collider to the background
//        NGUITools.AddWidgetCollider(go);
//
//        // Add an input script to the background and have it point to the label
//        UIInput input = go.AddComponent<UIInput>();
//        input.label = lbl;
//
//        return input;
//    }
//    #endregion //Input
//
//    #region //PopList
//    public static UIPopupList CreatePopList(GameObject parent, string name)
//    {
//        return CreateBasePopList(parent, name, true);
//    }
//
//    public static UIPopupList CreatePopMenu(GameObject parent, string name)
//    {
//        return CreateBasePopList(parent, name, false);
//    }
//
//    static UIPopupList CreateBasePopList(GameObject parent, string name, bool isDropDown)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//        GameObject go = NGUITools.AddChild(parent);
//        go.name = name;
//
//        UIAtlas.Sprite sphl = defaultAtlas.GetSprite("");
//        UIAtlas.Sprite spfg = defaultAtlas.GetSprite("");
//
//        Vector2 hlPadding = new Vector2(
//            Mathf.Max(4f, sphl.inner.xMin - sphl.outer.xMin),
//            Mathf.Max(4f, sphl.inner.yMin - sphl.outer.yMin));
//
//        Vector2 fgPadding = new Vector2(
//            Mathf.Max(4f, spfg.inner.xMin - spfg.outer.xMin),
//            Mathf.Max(4f, spfg.inner.yMin - spfg.outer.yMin));
//
//        // Background sprite
//        UISprite sprite = NGUITools.AddSprite(go, defaultAtlas, "");
//        sprite.depth = depth;
//        sprite.atlas = defaultAtlas;
//        sprite.transform.localScale = new Vector3(150f + fgPadding.x * 2f, defaultFont.size + fgPadding.y * 2f, 1f);
//        sprite.pivot = UIWidget.Pivot.Left;
//        sprite.MakePixelPerfect();
//        //sclae to the defualt
//        SetDefualtScale(sprite);
//
//        // Text label
//        UILabel lbl = NGUITools.AddWidget<UILabel>(go);
//        lbl.font = defaultFont;
//        lbl.text = go.name;
//        lbl.pivot = UIWidget.Pivot.Left;
//        lbl.cachedTransform.localPosition = new Vector3(fgPadding.x, 0f, 0f);
//        lbl.MakePixelPerfect();
//
//        // Add a collider
//        NGUITools.AddWidgetCollider(go);
//
//        // Add the popup list
//        UIPopupList list = go.AddComponent<UIPopupList>();
//        list.atlas = defaultAtlas;
//        list.font = defaultFont;
//        list.backgroundSprite = "";
//        list.highlightSprite = "";
//        list.padding = hlPadding;
//        if (isDropDown) list.textLabel = lbl;
//        for (int i = 0; i < 5; ++i) list.items.Add(isDropDown ? ("List Option " + i) : ("Menu Option " + i));
//
//        // Add the scripts
//        go.AddComponent<UIButton>().tweenTarget = sprite.gameObject;
//        go.AddComponent<UIButtonSound>();
//
//        return list;
//    }
//    #endregion //PopList
//
//    #region //ScrollBar
//    public static UIScrollBar CreateScrollBar(GameObject parent, string name, UIScrollBar.Direction direction)
//    {
//        int depth = NGUITools.CalculateNextDepth(parent);
//		GameObject	go = NGUITools.AddChild(parent);
//		go.name = name;
//
//		UISlicedSprite bg = NGUITools.AddWidget<UISlicedSprite>(go);
//		bg.name = "Background";
//		bg.depth = depth;
//		bg.atlas = defaultAtlas;
//		bg.transform.localScale = new Vector3(400f + bg.border.x + bg.border.z, 14f + bg.border.y + bg.border.w, 1f);
//		bg.MakePixelPerfect();
//
//		UISlicedSprite fg = NGUITools.AddWidget<UISlicedSprite>(go);
//		fg.name = "Foreground";
//        fg.atlas = defaultAtlas;
//
//		UIScrollBar sb = go.AddComponent<UIScrollBar>();
//		sb.background = bg;
//		sb.foreground = fg;
//        sb.direction = direction;
//		sb.barSize = 0.3f;
//		sb.scrollValue = 0.3f;
//		sb.ForceUpdate();
//
//		//if (mScrollCL)
//		{
//			NGUITools.AddWidgetCollider(bg.gameObject);
//			NGUITools.AddWidgetCollider(fg.gameObject);
//		}
//
//        return sb;
//    }
//
//    #endregion //ScrollBar
//
//    static void SetDefualtScale(UISprite sprite)
//    {
//        Texture tex = sprite.mainTexture;
//        sprite.transform.localScale = new Vector3(Mathf.Abs(sprite.outerUV.width * tex.width), Mathf.Abs(sprite.outerUV.height * tex.height), 1);
//    }
//
//    #endregion //Create UI
	
	#region //UI Resources
		
	public static UIAtlas GetAtlas(string atlasName)
	{
		string temp = atlasName.ToLower();
		if(atlasList.ContainsKey(temp))
			return atlasList[temp];
		
		return null;
	}
	
	public static UIFont GetFont(string fontName)
	{
		string temp = fontName.ToLower();
		if(fontList.ContainsKey(temp))
			return fontList[temp];
		
		return null;
	}
	
	public static Material GetMaterial(string materialName)
	{
		string temp = materialName.ToLower();
		if(materialList.ContainsKey(temp))
			return materialList[temp];
		
		return null;
	}

	public static GameObject GetEffect(string effectName)
	{
		string temp = effectName.ToLower();
		if(effectList.ContainsKey(temp))
			return effectList[temp];
		
		return null;
	}
	
	public static AudioClip GetAudio(string audioName)
	{
		string temp = audioName.ToLower();
		if(soundsList.ContainsKey(temp))
			return soundsList[temp];
		
		return null;
	}
	
	#endregion //UI Resources
}
#endif
